]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_template_source.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_template_source.php
1 <?php
2
3 /**
4  * Smarty Resource Data Object
5  * Meta Data Container for Template Files
6  *
7  * @package    Smarty
8  * @subpackage TemplateResources
9  * @author     Rodney Rehm
10  *
11  */
12 class Smarty_Template_Source
13 {
14     /**
15      * Unique Template ID
16      *
17      * @var string
18      */
19     public $uid = null;
20
21     /**
22      * Template Resource (Smarty_Internal_Template::$template_resource)
23      *
24      * @var string
25      */
26     public $resource = null;
27
28     /**
29      * Resource Type
30      *
31      * @var string
32      */
33     public $type = null;
34
35     /**
36      * Resource Name
37      *
38      * @var string
39      */
40     public $name = null;
41
42     /**
43      * Source Filepath
44      *
45      * @var string
46      */
47     public $filepath = null;
48
49     /**
50      * Source Timestamp
51      *
52      * @var integer
53      */
54     public $timestamp = null;
55
56     /**
57      * Source Existence
58      *
59      * @var boolean
60      */
61     public $exists = false;
62
63     /**
64      * Source File Base name
65      *
66      * @var string
67      */
68     public $basename = null;
69
70     /**
71      * The Components an extended template is made of
72      *
73      * @var \Smarty_Template_Source[]
74      */
75     public $components = null;
76
77     /**
78      * Resource Handler
79      *
80      * @var \Smarty_Resource
81      */
82     public $handler = null;
83
84     /**
85      * Smarty instance
86      *
87      * @var Smarty
88      */
89     public $smarty = null;
90
91     /**
92      * Resource is source
93      *
94      * @var bool
95      */
96     public $isConfig = false;
97
98     /**
99      * Template source content eventually set by default handler
100      *
101      * @var string
102      */
103     public $content = null;
104
105     /**
106      * Name of the Class to compile this resource's contents with
107      *
108      * @var string
109      */
110     public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
111
112     /**
113      * Name of the Class to tokenize this resource's contents with
114      *
115      * @var string
116      */
117     public $template_lexer_class = 'Smarty_Internal_Templatelexer';
118
119     /**
120      * Name of the Class to parse this resource's contents with
121      *
122      * @var string
123      */
124     public $template_parser_class = 'Smarty_Internal_Templateparser';
125
126     /**
127      * create Source Object container
128      *
129      * @param Smarty_Resource $handler  Resource Handler this source object communicates with
130      * @param Smarty          $smarty   Smarty instance this source object belongs to
131      * @param string          $resource full template_resource
132      * @param string          $type     type of resource
133      * @param string          $name     resource name
134      *
135      */
136     public function __construct(Smarty $smarty, $resource, $type, $name)
137     {
138         $this->handler =
139             isset($smarty->_cache[ 'resource_handlers' ][ $type ]) ? $smarty->_cache[ 'resource_handlers' ][ $type ] :
140                 Smarty_Resource::load($smarty, $type);
141         $this->smarty = $smarty;
142         $this->resource = $resource;
143         $this->type = $type;
144         $this->name = $name;
145     }
146
147     /**
148      * initialize Source Object for given resource
149      * Either [$_template] or [$smarty, $template_resource] must be specified
150      *
151      * @param  Smarty_Internal_Template $_template         template object
152      * @param  Smarty                   $smarty            smarty object
153      * @param  string                   $template_resource resource identifier
154      *
155      * @return Smarty_Template_Source Source Object
156      * @throws SmartyException
157      */
158     public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null,
159                                 $template_resource = null)
160     {
161         if ($_template) {
162             $smarty = $_template->smarty;
163             $template_resource = $_template->template_resource;
164         }
165         if (empty($template_resource)) {
166             throw new SmartyException('Source: Missing  name');
167         }
168         // parse resource_name, load resource handler, identify unique resource name
169         if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]([\s\S]*)$/', $template_resource, $match)) {
170             $type = $match[ 1 ];
171             $name = $match[ 2 ];
172         } else {
173             // no resource given, use default
174             // or single character before the colon is not a resource type, but part of the filepath
175             $type = $smarty->default_resource_type;
176             $name = $template_resource;
177         }
178         // create new source  object
179         $source = new Smarty_Template_Source($smarty, $template_resource, $type, $name);
180         $source->handler->populate($source, $_template);
181         if (!$source->exists && isset($_template->smarty->default_template_handler_func)) {
182             Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
183             $source->handler->populate($source, $_template);
184         }
185         return $source;
186     }
187
188     /**
189      * Get source time stamp
190      *
191      * @return int
192      */
193     public function getTimeStamp()
194     {
195         if (!isset($this->timestamp)) {
196             $this->handler->populateTimestamp($this);
197         }
198         return $this->timestamp;
199     }
200
201     /**
202      * Get source content
203      *
204      * @return string
205      */
206     public function getContent()
207     {
208         return isset($this->content) ? $this->content : $this->handler->getContent($this);
209     }
210 }