您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

smarty_internal_resource_stream.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Resource Stream
  4. * Implements the streams as resource for Smarty template
  5. *
  6. * @package Smarty
  7. * @subpackage TemplateResources
  8. * @author Uwe Tews
  9. * @author Rodney Rehm
  10. */
  11. /**
  12. * Smarty Internal Plugin Resource Stream
  13. * Implements the streams as resource for Smarty template
  14. *
  15. * @link http://php.net/streams
  16. * @package Smarty
  17. * @subpackage TemplateResources
  18. */
  19. class Smarty_Internal_Resource_Stream extends Smarty_Resource_Recompiled
  20. {
  21. /**
  22. * populate Source Object with meta data from Resource
  23. *
  24. * @param Smarty_Template_Source $source source object
  25. * @param Smarty_Internal_Template $_template template object
  26. *
  27. * @return void
  28. */
  29. public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
  30. {
  31. if (strpos($source->resource, '://') !== false) {
  32. $source->filepath = $source->resource;
  33. } else {
  34. $source->filepath = str_replace(':', '://', $source->resource);
  35. }
  36. $source->uid = false;
  37. $source->content = $this->getContent($source);
  38. $source->timestamp = false;
  39. $source->exists = !!$source->content;
  40. }
  41. /**
  42. * Load template's source from stream into current template object
  43. *
  44. * @param Smarty_Template_Source $source source object
  45. *
  46. * @return string template source
  47. * @throws SmartyException if source cannot be loaded
  48. */
  49. public function getContent(Smarty_Template_Source $source)
  50. {
  51. $t = '';
  52. // the availability of the stream has already been checked in Smarty_Resource::fetch()
  53. $fp = fopen($source->filepath, 'r+');
  54. if ($fp) {
  55. while (!feof($fp) && ($current_line = fgets($fp)) !== false) {
  56. $t .= $current_line;
  57. }
  58. fclose($fp);
  59. return $t;
  60. } else {
  61. return false;
  62. }
  63. }
  64. /**
  65. * modify resource_name according to resource handlers specifications
  66. *
  67. * @param Smarty $smarty Smarty instance
  68. * @param string $resource_name resource_name to make unique
  69. * @param boolean $isConfig flag for config resource
  70. *
  71. * @return string unique resource name
  72. */
  73. public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
  74. {
  75. return get_class($this) . '#' . $resource_name;
  76. }
  77. }