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