ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_Loader_Chain Class Reference

Loads templates from other loaders. More...

+ Inheritance diagram for Twig_Loader_Chain:
+ Collaboration diagram for Twig_Loader_Chain:

Public Member Functions

 __construct (array $loaders=array())
 
 addLoader (Twig_LoaderInterface $loader)
 
 getSource ($name)
 Gets the source code of a template, given its name. More...
 
 getSourceContext ($name)
 Returns the source context for a given template logical name. More...
 
 exists ($name)
 Check if we have the source code of a template, given its name. More...
 
 getCacheKey ($name)
 Gets the cache key to use for the cache for a given template name. More...
 
 isFresh ($name, $time)
 Returns true if the template is still fresh. More...
 

Protected Attributes

 $loaders = array()
 

Private Attributes

 $hasSourceCache = array()
 

Detailed Description

Loads templates from other loaders.

Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com

Definition at line 19 of file Chain.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Loader_Chain::__construct ( array  $loaders = array())
Parameters
Twig_LoaderInterface[]$loaders

Definition at line 27 of file Chain.php.

References $loader, $loaders, and addLoader().

28  {
29  foreach ($loaders as $loader) {
30  $this->addLoader($loader);
31  }
32  }
addLoader(Twig_LoaderInterface $loader)
Definition: Chain.php:34
+ Here is the call graph for this function:

Member Function Documentation

◆ addLoader()

Twig_Loader_Chain::addLoader ( Twig_LoaderInterface  $loader)

Definition at line 34 of file Chain.php.

References $loader, and array.

Referenced by __construct().

35  {
36  $this->loaders[] = $loader;
37  $this->hasSourceCache = array();
38  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ exists()

Twig_Loader_Chain::exists (   $name)

Check if we have the source code of a template, given its name.

Parameters
string$nameThe name of the template to check if we can load
Returns
bool If the template source code is handled by this loader or not

Implements Twig_ExistsLoaderInterface.

Definition at line 82 of file Chain.php.

References $loader, $name, and string.

83  {
84  $name = (string) $name;
85 
86  if (isset($this->hasSourceCache[$name])) {
87  return $this->hasSourceCache[$name];
88  }
89 
90  foreach ($this->loaders as $loader) {
91  if ($loader instanceof Twig_ExistsLoaderInterface) {
92  if ($loader->exists($name)) {
93  return $this->hasSourceCache[$name] = true;
94  }
95 
96  continue;
97  }
98 
99  try {
100  if ($loader instanceof Twig_SourceContextLoaderInterface) {
101  $loader->getSourceContext($name);
102  } else {
103  $loader->getSource($name);
104  }
105 
106  return $this->hasSourceCache[$name] = true;
107  } catch (Twig_Error_Loader $e) {
108  }
109  }
110 
111  return $this->hasSourceCache[$name] = false;
112  }
Add rich text string
Exception thrown when an error occurs during template loading.
Definition: Loader.php:25
if($format !==null) $name
Definition: metadata.php:146
Adds an exists() method for loaders.
Adds a getSourceContext() method for loaders.

◆ getCacheKey()

Twig_Loader_Chain::getCacheKey (   $name)

Gets the cache key to use for the cache for a given template name.

Parameters
string$nameThe name of the template to load
Returns
string The cache key
Exceptions
Twig_Error_LoaderWhen $name is not found

Implements Twig_LoaderInterface.

Definition at line 114 of file Chain.php.

References $exceptions, $loader, $name, array, and Twig_ExistsLoaderInterface\exists().

115  {
116  $exceptions = array();
117  foreach ($this->loaders as $loader) {
118  if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
119  continue;
120  }
121 
122  try {
123  return $loader->getCacheKey($name);
124  } catch (Twig_Error_Loader $e) {
125  $exceptions[] = get_class($loader).': '.$e->getMessage();
126  }
127  }
128 
129  throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
130  }
exists($name)
Check if we have the source code of a template, given its name.
Exception thrown when an error occurs during template loading.
Definition: Loader.php:25
if($format !==null) $name
Definition: metadata.php:146
Adds an exists() method for loaders.
Create styles array
The data for the language used.
$exceptions
Definition: Utf8Test.php:67
+ Here is the call graph for this function:

◆ getSource()

Twig_Loader_Chain::getSource (   $name)

Gets the source code of a template, given its name.

Parameters
string$nameThe name of the template to load
Returns
string The template source code
Exceptions
Twig_Error_LoaderWhen $name is not found
Deprecated:
since 1.27 (to be removed in 2.0), implement Twig_SourceContextLoaderInterface

Implements Twig_LoaderInterface.

Definition at line 40 of file Chain.php.

References $exceptions, $loader, $name, array, and Twig_ExistsLoaderInterface\exists().

41  {
42  @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
43 
44  $exceptions = array();
45  foreach ($this->loaders as $loader) {
46  if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
47  continue;
48  }
49 
50  try {
51  return $loader->getSource($name);
52  } catch (Twig_Error_Loader $e) {
53  $exceptions[] = $e->getMessage();
54  }
55  }
56 
57  throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
58  }
exists($name)
Check if we have the source code of a template, given its name.
Exception thrown when an error occurs during template loading.
Definition: Loader.php:25
if($format !==null) $name
Definition: metadata.php:146
Adds an exists() method for loaders.
Create styles array
The data for the language used.
$exceptions
Definition: Utf8Test.php:67
+ Here is the call graph for this function:

◆ getSourceContext()

Twig_Loader_Chain::getSourceContext (   $name)

Returns the source context for a given template logical name.

Parameters
string$nameThe template logical name
Returns
Twig_Source
Exceptions
Twig_Error_LoaderWhen $name is not found

Implements Twig_SourceContextLoaderInterface.

Definition at line 60 of file Chain.php.

References $exceptions, $loader, $name, array, and Twig_ExistsLoaderInterface\exists().

61  {
62  $exceptions = array();
63  foreach ($this->loaders as $loader) {
64  if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
65  continue;
66  }
67 
68  try {
69  if ($loader instanceof Twig_SourceContextLoaderInterface) {
70  return $loader->getSourceContext($name);
71  }
72 
73  return new Twig_Source($loader->getSource($name), $name);
74  } catch (Twig_Error_Loader $e) {
75  $exceptions[] = $e->getMessage();
76  }
77  }
78 
79  throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
80  }
exists($name)
Check if we have the source code of a template, given its name.
Exception thrown when an error occurs during template loading.
Definition: Loader.php:25
if($format !==null) $name
Definition: metadata.php:146
Adds an exists() method for loaders.
Adds a getSourceContext() method for loaders.
Create styles array
The data for the language used.
Holds information about a non-compiled Twig template.
Definition: Source.php:19
$exceptions
Definition: Utf8Test.php:67
+ Here is the call graph for this function:

◆ isFresh()

Twig_Loader_Chain::isFresh (   $name,
  $time 
)

Returns true if the template is still fresh.

Parameters
string$nameThe template name
int$timeTimestamp of the last modification time of the cached template
Returns
bool true if the template is fresh, false otherwise
Exceptions
Twig_Error_LoaderWhen $name is not found

Implements Twig_LoaderInterface.

Definition at line 132 of file Chain.php.

References $exceptions, $loader, $name, $time, array, and Twig_ExistsLoaderInterface\exists().

133  {
134  $exceptions = array();
135  foreach ($this->loaders as $loader) {
136  if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
137  continue;
138  }
139 
140  try {
141  return $loader->isFresh($name, $time);
142  } catch (Twig_Error_Loader $e) {
143  $exceptions[] = get_class($loader).': '.$e->getMessage();
144  }
145  }
146 
147  throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
148  }
exists($name)
Check if we have the source code of a template, given its name.
Exception thrown when an error occurs during template loading.
Definition: Loader.php:25
$time
Definition: cron.php:21
if($format !==null) $name
Definition: metadata.php:146
Adds an exists() method for loaders.
Create styles array
The data for the language used.
$exceptions
Definition: Utf8Test.php:67
+ Here is the call graph for this function:

Field Documentation

◆ $hasSourceCache

Twig_Loader_Chain::$hasSourceCache = array()
private

Definition at line 21 of file Chain.php.

◆ $loaders

Twig_Loader_Chain::$loaders = array()
protected

Definition at line 22 of file Chain.php.

Referenced by __construct().


The documentation for this class was generated from the following file: