PEEL Shopping
Open source ecommerce : PEEL Shopping
Chain.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Twig.
5  *
6  * (c) 2011 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 
18 {
19  private $hasSourceCache = array();
20  protected $loaders;
21 
27  public function __construct(array $loaders = array())
28  {
29  $this->loaders = array();
30  foreach ($loaders as $loader) {
31  $this->addLoader($loader);
32  }
33  }
34 
40  public function addLoader(Twig_LoaderInterface $loader)
41  {
42  $this->loaders[] = $loader;
43  $this->hasSourceCache = array();
44  }
45 
49  public function getSource($name)
50  {
51  $exceptions = array();
52  foreach ($this->loaders as $loader) {
53  if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
54  continue;
55  }
56 
57  try {
58  return $loader->getSource($name);
59  } catch (Twig_Error_Loader $e) {
60  $exceptions[] = $e->getMessage();
61  }
62  }
63 
64  throw new Twig_Error_Loader(sprintf('Template "%s" is not defined (%s).', $name, implode(', ', $exceptions)));
65  }
66 
70  public function exists($name)
71  {
72  $name = (string) $name;
73 
74  if (isset($this->hasSourceCache[$name])) {
75  return $this->hasSourceCache[$name];
76  }
77 
78  foreach ($this->loaders as $loader) {
79  if ($loader instanceof Twig_ExistsLoaderInterface) {
80  if ($loader->exists($name)) {
81  return $this->hasSourceCache[$name] = true;
82  }
83 
84  continue;
85  }
86 
87  try {
88  $loader->getSource($name);
89 
90  return $this->hasSourceCache[$name] = true;
91  } catch (Twig_Error_Loader $e) {
92  }
93  }
94 
95  return $this->hasSourceCache[$name] = false;
96  }
97 
101  public function getCacheKey($name)
102  {
103  $exceptions = array();
104  foreach ($this->loaders as $loader) {
105  if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
106  continue;
107  }
108 
109  try {
110  return $loader->getCacheKey($name);
111  } catch (Twig_Error_Loader $e) {
112  $exceptions[] = get_class($loader).': '.$e->getMessage();
113  }
114  }
115 
116  throw new Twig_Error_Loader(sprintf('Template "%s" is not defined (%s).', $name, implode(' ', $exceptions)));
117  }
118 
122  public function isFresh($name, $time)
123  {
124  $exceptions = array();
125  foreach ($this->loaders as $loader) {
126  if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
127  continue;
128  }
129 
130  try {
131  return $loader->isFresh($name, $time);
132  } catch (Twig_Error_Loader $e) {
133  $exceptions[] = get_class($loader).': '.$e->getMessage();
134  }
135  }
136 
137  throw new Twig_Error_Loader(sprintf('Template "%s" is not defined (%s).', $name, implode(' ', $exceptions)));
138  }
139 }
getSource($name)
{Gets the source code of a template, given its name.The name of the template to loadstring The templa...
Definition: Chain.php:49
addLoader(Twig_LoaderInterface $loader)
Adds a loader instance.
Definition: Chain.php:40
exists($name)
{Check if we have the source code of a template, given its name.The name of the template to check if ...
Definition: Chain.php:70
getCacheKey($name)
{Gets the cache key to use for the cache for a given template name.The name of the template to loadst...
Definition: Chain.php:101
Adds an exists() method for loaders.
Interface all loaders must implement.
Loads templates from other loaders.
Definition: Chain.php:17
exists($name)
Check if we have the source code of a template, given its name.
__construct(array $loaders=array())
Constructor.
Definition: Chain.php:27
Exception thrown when an error occurs during template loading.
Definition: Loader.php:25
isFresh($name, $time)
{Returns true if the template is still fresh.The template name The last modification time of the cach...
Definition: Chain.php:122

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:18 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.