3 * Smarty Internal Plugin Resource Stream
4 * Implements the streams as resource for Smarty template
7 * @subpackage TemplateResources
13 * Smarty Internal Plugin Resource Stream
14 * Implements the streams as resource for Smarty template
16 * @link http://php.net/streams
18 * @subpackage TemplateResources
20 class Smarty_Internal_Resource_Stream extends Smarty_Resource_Recompiled
23 * populate Source Object with meta data from Resource
25 * @param Smarty_Template_Source $source source object
26 * @param Smarty_Internal_Template $_template template object
30 public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
32 if (strpos($source->resource, '://') !== false) {
33 $source->filepath = $source->resource;
35 $source->filepath = str_replace(':', '://', $source->resource);
38 $source->content = $this->getContent($source);
39 $source->timestamp = false;
40 $source->exists = !!$source->content;
44 * Load template's source from stream into current template object
46 * @param Smarty_Template_Source $source source object
48 * @return string template source
49 * @throws SmartyException if source cannot be loaded
51 public function getContent(Smarty_Template_Source $source)
54 // the availability of the stream has already been checked in Smarty_Resource::fetch()
55 $fp = fopen($source->filepath, 'r+');
57 while (!feof($fp) && ($current_line = fgets($fp)) !== false) {
69 * modify resource_name according to resource handlers specifications
71 * @param Smarty $smarty Smarty instance
72 * @param string $resource_name resource_name to make unique
73 * @param boolean $is_config flag for config resource
75 * @return string unique resource name
77 protected function buildUniqueResourceName(Smarty $smarty, $resource_name, $is_config = false)
79 return get_class($this) . '#' . $resource_name;