smarty_internal_resource_stream.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Resource Stream
  4. *
  5. * Implements the streams as resource for Smarty template
  6. *
  7. * @package Smarty
  8. * @subpackage TemplateResources
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Resource Stream
  13. */
  14. class Smarty_Internal_Resource_Stream {
  15. public function __construct($smarty)
  16. {
  17. $this->smarty = $smarty;
  18. }
  19. // classes used for compiling Smarty templates from file resource
  20. public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
  21. public $template_lexer_class = 'Smarty_Internal_Templatelexer';
  22. public $template_parser_class = 'Smarty_Internal_Templateparser';
  23. // properties
  24. public $usesCompiler = true;
  25. public $isEvaluated = true;
  26. /**
  27. * Return flag if template source is existing
  28. *
  29. * @return boolean true
  30. */
  31. public function isExisting($template)
  32. {
  33. if ($template->getTemplateSource() == '') {
  34. return false;
  35. } else {
  36. return true;
  37. }
  38. }
  39. /**
  40. * Get filepath to template source
  41. *
  42. * @param object $_template template object
  43. * @return string return 'string' as template source is not a file
  44. */
  45. public function getTemplateFilepath($_template)
  46. {
  47. // no filepath for strings
  48. // return resource name for compiler error messages
  49. return str_replace(':', '://', $_template->template_resource);
  50. }
  51. /**
  52. * Get timestamp to template source
  53. *
  54. * @param object $_template template object
  55. * @return boolean false as string resources have no timestamp
  56. */
  57. public function getTemplateTimestamp($_template)
  58. {
  59. // strings must always be compiled and have no timestamp
  60. return false;
  61. }
  62. /**
  63. * Retuen template source from resource name
  64. *
  65. * @param object $_template template object
  66. * @return string content of template source
  67. */
  68. public function getTemplateSource($_template)
  69. {
  70. // return template string
  71. $_template->template_source = '';
  72. $fp = fopen(str_replace(':', '://', $_template->template_resource),'r+');
  73. while (!feof($fp)) {
  74. $_template->template_source .= fgets($fp);
  75. }
  76. fclose($fp);
  77. return true;
  78. }
  79. /**
  80. * Get filepath to compiled template
  81. *
  82. * @param object $_template template object
  83. * @return boolean return false as compiled template is not stored
  84. */
  85. public function getCompiledFilepath($_template)
  86. {
  87. // no filepath for strings
  88. return false;
  89. }
  90. }
  91. ?>