]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_resource_registered.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_resource_registered.php
1 <?php
2 /**
3  * Smarty Internal Plugin Resource Registered
4  *
5  * @package    Smarty
6  * @subpackage TemplateResources
7  * @author     Uwe Tews
8  * @author     Rodney Rehm
9  */
10
11 /**
12  * Smarty Internal Plugin Resource Registered
13  * Implements the registered resource for Smarty template
14  *
15  * @package    Smarty
16  * @subpackage TemplateResources
17  * @deprecated
18  */
19 class Smarty_Internal_Resource_Registered extends Smarty_Resource
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         $source->filepath = $source->type . ':' . $source->name;
32         $source->uid = sha1($source->filepath . $source->smarty->_joined_template_dir);
33         $source->timestamp = $this->getTemplateTimestamp($source);
34         $source->exists = !!$source->timestamp;
35     }
36
37     /**
38      * populate Source Object with timestamp and exists from Resource
39      *
40      * @param  Smarty_Template_Source $source source object
41      *
42      * @return void
43      */
44     public function populateTimestamp(Smarty_Template_Source $source)
45     {
46         $source->timestamp = $this->getTemplateTimestamp($source);
47         $source->exists = !!$source->timestamp;
48     }
49
50     /**
51      * Get timestamp (epoch) the template source was modified
52      *
53      * @param  Smarty_Template_Source $source source object
54      *
55      * @return integer|boolean        timestamp (epoch) the template was modified, false if resources has no timestamp
56      */
57     public function getTemplateTimestamp(Smarty_Template_Source $source)
58     {
59         // return timestamp
60         $time_stamp = false;
61         call_user_func_array($source->smarty->registered_resources[ $source->type ][ 0 ][ 1 ],
62                              array($source->name, &$time_stamp, $source->smarty));
63
64         return is_numeric($time_stamp) ? (int) $time_stamp : $time_stamp;
65     }
66
67     /**
68      * Load template's source by invoking the registered callback into current template object
69      *
70      * @param  Smarty_Template_Source $source source object
71      *
72      * @return string                 template source
73      * @throws SmartyException        if source cannot be loaded
74      */
75     public function getContent(Smarty_Template_Source $source)
76     {
77         // return template string
78         $content = null;
79         $t = call_user_func_array($source->smarty->registered_resources[ $source->type ][ 0 ][ 0 ],
80                                   array($source->name, &$content, $source->smarty));
81         if (is_bool($t) && !$t) {
82             throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
83         }
84
85         return $content;
86     }
87
88     /**
89      * Determine basename for compiled filename
90      *
91      * @param  Smarty_Template_Source $source source object
92      *
93      * @return string                 resource's basename
94      */
95     public function getBasename(Smarty_Template_Source $source)
96     {
97         return basename($source->name);
98     }
99 }