ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Array.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
27 {
28  protected $templates = array();
29 
33  public function __construct(array $templates = array())
34  {
35  $this->templates = $templates;
36  }
37 
44  public function setTemplate($name, $template)
45  {
46  $this->templates[(string) $name] = $template;
47  }
48 
49  public function getSource($name)
50  {
51  @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
52 
53  $name = (string) $name;
54  if (!isset($this->templates[$name])) {
55  throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
56  }
57 
58  return $this->templates[$name];
59  }
60 
61  public function getSourceContext($name)
62  {
63  $name = (string) $name;
64  if (!isset($this->templates[$name])) {
65  throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
66  }
67 
68  return new Twig_Source($this->templates[$name], $name);
69  }
70 
71  public function exists($name)
72  {
73  return isset($this->templates[(string) $name]);
74  }
75 
76  public function getCacheKey($name)
77  {
78  $name = (string) $name;
79  if (!isset($this->templates[$name])) {
80  throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
81  }
82 
83  return $name.':'.$this->templates[$name];
84  }
85 
86  public function isFresh($name, $time)
87  {
88  $name = (string) $name;
89  if (!isset($this->templates[$name])) {
90  throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
91  }
92 
93  return true;
94  }
95 }
96 
97 class_alias('Twig_Loader_Array', 'Twig\Loader\ArrayLoader', false);
$template
Exception thrown when an error occurs during template loading.
Definition: Loader.php:25
__construct(array $templates=array())
Definition: Array.php:33
getSource($name)
Gets the source code of a template, given its name.
Definition: Array.php:49
$time
Definition: cron.php:21
Adds an exists() method for loaders.
Adds a getSourceContext() method for loaders.
getSourceContext($name)
Returns the source context for a given template logical name.
Definition: Array.php:61
getCacheKey($name)
Gets the cache key to use for the cache for a given template name.
Definition: Array.php:76
isFresh($name, $time)
Returns true if the template is still fresh.
Definition: Array.php:86
Holds information about a non-compiled Twig template.
Definition: Source.php:19
setTemplate($name, $template)
Adds or overrides a template.
Definition: Array.php:44
Interface all loaders must implement.
Loads a template from an array.
Definition: Array.php:26
exists($name)
Check if we have the source code of a template, given its name.
Definition: Array.php:71