libs/sysplugins/smarty_resource.php Quellcode

smarty_resource.php
gehe zur Dokumentation dieser Datei
1 <?php
17 abstract class Smarty_Resource
18 {
24  public $uncompiled = false;
25 
31  public $recompiled = false;
37  public $handler = null;
43  public static $sources = array();
49  public static $compileds = array();
55  protected static $sysplugins = array(
56  'file' => 'smarty_internal_resource_file.php',
57  'string' => 'smarty_internal_resource_string.php',
58  'extends' => 'smarty_internal_resource_extends.php',
59  'stream' => 'smarty_internal_resource_stream.php',
60  'eval' => 'smarty_internal_resource_eval.php',
61  'php' => 'smarty_internal_resource_php.php'
62  );
63 
69  public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
70 
76  public $template_lexer_class = 'Smarty_Internal_Templatelexer';
77 
83  public $template_parser_class = 'Smarty_Internal_Templateparser';
84 
94  abstract public function getContent(Smarty_Template_Source $source);
95 
102  abstract public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null);
103 
109  public function populateTimestamp(Smarty_Template_Source $source)
110  {
111  // intentionally left blank
112  }
113 
123  public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
124  {
125  if ($isConfig) {
126  return get_class($this) . '#' . $smarty->joined_config_dir . '#' . $resource_name;
127  } else {
128  return get_class($this) . '#' . $smarty->joined_template_dir . '#' . $resource_name;
129  }
130  }
131 
139  public function getBasename(Smarty_Template_Source $source)
140  {
141  return null;
142  }
143 
153  public static function load(Smarty $smarty, $type)
154  {
155  // try smarty's cache
156  if (isset($smarty->_resource_handlers[$type])) {
157  return $smarty->_resource_handlers[$type];
158  }
159 
160  // try registered resource
161  if (isset($smarty->registered_resources[$type])) {
162  if ($smarty->registered_resources[$type] instanceof Smarty_Resource) {
163  $smarty->_resource_handlers[$type] = $smarty->registered_resources[$type];
164  } else {
165  $smarty->_resource_handlers[$type] = new Smarty_Internal_Resource_Registered();
166  }
167 
168  return $smarty->_resource_handlers[$type];
169  }
170 
171  // try sysplugins dir
172  if (isset(self::$sysplugins[$type])) {
173  $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
174  if (!class_exists($_resource_class, false)) {
175  require SMARTY_SYSPLUGINS_DIR . self::$sysplugins[$type];
176  }
177  return $smarty->_resource_handlers[$type] = new $_resource_class();
178  }
179 
180  // try plugins dir
181  $_resource_class = 'Smarty_Resource_' . ucfirst($type);
182  if ($smarty->loadPlugin($_resource_class)) {
183  if (class_exists($_resource_class, false)) {
184  return $smarty->_resource_handlers[$type] = new $_resource_class();
185  } else {
186  $smarty->registerResource($type, array(
187  "smarty_resource_{$type}_source",
188  "smarty_resource_{$type}_timestamp",
189  "smarty_resource_{$type}_secure",
190  "smarty_resource_{$type}_trusted"
191  ));
192  // give it another try, now that the resource is registered properly
193  return self::load($smarty, $type);
194  }
195  }
196 
197  // try streams
198  $_known_stream = stream_get_wrappers();
199  if (in_array($type, $_known_stream)) {
200  // is known stream
201  if (is_object($smarty->security_policy)) {
202  $smarty->security_policy->isTrustedStream($type);
203  }
204  return $smarty->_resource_handlers[$type] = new Smarty_Internal_Resource_Stream();;
205  }
206 
207  // TODO: try default_(template|config)_handler
208 
209  // give up
210  throw new SmartyException("Unknown resource type '{$type}'");
211  }
212 
222  public static function parseResourceName($resource_name, $default_resource)
223  {
224  if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]/', $resource_name, $match)) {
225  $type = $match[1];
226  $name = substr($resource_name, strlen($match[0]));
227  } else {
228  // no resource given, use default
229  // or single character before the colon is not a resource type, but part of the filepath
230  $type = $default_resource;
231  $name = $resource_name;
232 
233  }
234  return array($name, $type);
235  }
236 
254  public static function getUniqueTemplateName($template, $template_resource)
255  {
256  $smarty = isset($template->smarty) ? $template->smarty : $template;
257  list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type);
258  // TODO: optimize for Smarty's internal resource types
259  $resource = Smarty_Resource::load($smarty, $type);
260  // go relative to a given template?
261  $_file_is_dotted = $name[0] == '.' && ($name[1] == '.' || $name[1] == '/');
262  if ($template instanceof Smarty_Internal_Template && $_file_is_dotted && ($template->source->type == 'file' || $template->parent->source->type == 'extends')) {
263  $name = dirname($template->source->filepath) . DS . $name;
264  }
265  return $resource->buildUniqueResourceName($smarty, $name);
266  }
267 
279  public static function source(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null)
280  {
281  return Smarty_Template_Source::load($_template, $smarty, $template_resource);
282  }
283 }
284 




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.