Revision 1852
Added by darkviper almost 12 years ago
Template.php | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
abstract class Twig_Template implements Twig_TemplateInterface |
20 | 20 |
{ |
21 |
static protected $cache = array();
|
|
21 |
protected static $cache = array();
|
|
22 | 22 |
|
23 | 23 |
protected $parent; |
24 | 24 |
protected $parents; |
... | ... | |
264 | 264 |
try { |
265 | 265 |
$this->doDisplay($context, $blocks); |
266 | 266 |
} catch (Twig_Error $e) { |
267 |
if (!$e->getTemplateFile()) { |
|
268 |
$e->setTemplateFile($this->getTemplateName()); |
|
269 |
} |
|
270 |
|
|
271 |
// this is mostly useful for Twig_Error_Loader exceptions |
|
272 |
// see Twig_Error_Loader |
|
273 |
if (false === $e->getTemplateLine()) { |
|
274 |
$e->setTemplateLine(-1); |
|
275 |
$e->guess(); |
|
276 |
} |
|
277 |
|
|
267 | 278 |
throw $e; |
268 | 279 |
} catch (Exception $e) { |
269 | 280 |
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, null, $e); |
... | ... | |
284 | 295 |
* This method is for internal use only and should never be called |
285 | 296 |
* directly. |
286 | 297 |
* |
287 |
* This method should not be overriden in a sub-class as this is an |
|
298 |
* This method should not be overridden in a sub-class as this is an
|
|
288 | 299 |
* implementation detail that has been introduced to optimize variable |
289 | 300 |
* access for versions of PHP before 5.4. This is not a way to override |
290 | 301 |
* the way to get a variable value. |
... | ... | |
304 | 315 |
return null; |
305 | 316 |
} |
306 | 317 |
|
307 |
throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist', $item)); |
|
318 |
throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist', $item), -1, $this->getTemplateName());
|
|
308 | 319 |
} |
309 | 320 |
|
310 | 321 |
return $context[$item]; |
... | ... | |
326 | 337 |
*/ |
327 | 338 |
protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) |
328 | 339 |
{ |
329 |
$item = (string) $item; |
|
340 |
$item = ctype_digit((string) $item) ? (int) $item : (string) $item;
|
|
330 | 341 |
|
331 | 342 |
// array |
332 | 343 |
if (Twig_TemplateInterface::METHOD_CALL !== $type) { |
... | ... | |
350 | 361 |
} |
351 | 362 |
|
352 | 363 |
if (is_object($object)) { |
353 |
throw new Twig_Error_Runtime(sprintf('Key "%s" in object (with ArrayAccess) of type "%s" does not exist', $item, get_class($object))); |
|
364 |
throw new Twig_Error_Runtime(sprintf('Key "%s" in object (with ArrayAccess) of type "%s" does not exist', $item, get_class($object)), -1, $this->getTemplateName());
|
|
354 | 365 |
} elseif (is_array($object)) { |
355 |
throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $item, implode(', ', array_keys($object)))); |
|
366 |
throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $item, implode(', ', array_keys($object))), -1, $this->getTemplateName());
|
|
356 | 367 |
} else { |
357 |
throw new Twig_Error_Runtime(sprintf('Impossible to access a key ("%s") on a "%s" variable', $item, gettype($object))); |
|
368 |
throw new Twig_Error_Runtime(sprintf('Impossible to access a key ("%s") on a "%s" variable', $item, gettype($object)), -1, $this->getTemplateName());
|
|
358 | 369 |
} |
359 | 370 |
} |
360 | 371 |
} |
... | ... | |
368 | 379 |
return null; |
369 | 380 |
} |
370 | 381 |
|
371 |
throw new Twig_Error_Runtime(sprintf('Item "%s" for "%s" does not exist', $item, is_array($object) ? 'Array' : $object)); |
|
382 |
throw new Twig_Error_Runtime(sprintf('Item "%s" for "%s" does not exist', $item, is_array($object) ? 'Array' : $object), -1, $this->getTemplateName());
|
|
372 | 383 |
} |
373 | 384 |
|
374 | 385 |
$class = get_class($object); |
375 | 386 |
|
376 | 387 |
// object property |
377 | 388 |
if (Twig_TemplateInterface::METHOD_CALL !== $type) { |
378 |
/* apparently, this is not needed as this is already covered by the array_key_exists() call below |
|
379 |
if (!isset(self::$cache[$class]['properties'])) { |
|
380 |
foreach (get_object_vars($object) as $k => $v) { |
|
381 |
self::$cache[$class]['properties'][$k] = true; |
|
382 |
} |
|
383 |
} |
|
384 |
*/ |
|
385 |
|
|
386 | 389 |
if (isset($object->$item) || array_key_exists($item, $object)) { |
387 | 390 |
if ($isDefinedTest) { |
388 | 391 |
return true; |
... | ... | |
419 | 422 |
return null; |
420 | 423 |
} |
421 | 424 |
|
422 |
throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist', $item, get_class($object))); |
|
425 |
throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist', $item, get_class($object)), -1, $this->getTemplateName());
|
|
423 | 426 |
} |
424 | 427 |
|
425 | 428 |
if ($isDefinedTest) { |
... | ... | |
432 | 435 |
|
433 | 436 |
$ret = call_user_func_array(array($object, $method), $arguments); |
434 | 437 |
|
435 |
// hack to be removed when macro calls are refactored |
|
438 |
// useful when calling a template method from a template |
|
439 |
// this is not supported but unfortunately heavily used in the Symfony profiler |
|
436 | 440 |
if ($object instanceof Twig_TemplateInterface) { |
437 | 441 |
return $ret === '' ? '' : new Twig_Markup($ret, $this->env->getCharset()); |
438 | 442 |
} |
... | ... | |
443 | 447 |
/** |
444 | 448 |
* This method is only useful when testing Twig. Do not use it. |
445 | 449 |
*/ |
446 |
static public function clearCache()
|
|
450 |
public static function clearCache()
|
|
447 | 451 |
{ |
448 | 452 |
self::$cache = array(); |
449 | 453 |
} |
Also available in: Unified diff
updated Twig template engine to stable version 1.11.1 step2