PEEL Shopping
Open source ecommerce : PEEL Shopping
Template.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Twig.
5  *
6  * (c) 2009 Fabien Potencier
7  * (c) 2009 Armin Ronacher
8  *
9  * For the full copyright and license information, please view the LICENSE
10  * file that was distributed with this source code.
11  */
12 
18 abstract class Twig_Template implements Twig_TemplateInterface
19 {
20  protected static $cache = array();
21 
22  protected $parent;
23  protected $parents;
24  protected $env;
25  protected $blocks;
26  protected $traits;
27 
34  {
35  $this->env = $env;
36  $this->blocks = array();
37  $this->traits = array();
38  }
39 
45  abstract public function getTemplateName();
46 
50  public function getEnvironment()
51  {
52  return $this->env;
53  }
54 
63  public function getParent(array $context)
64  {
65  if (null !== $this->parent) {
66  return $this->parent;
67  }
68 
69  $parent = $this->doGetParent($context);
70  if (false === $parent) {
71  return false;
72  } elseif ($parent instanceof Twig_Template) {
73  $name = $parent->getTemplateName();
74  $this->parents[$name] = $parent;
75  $parent = $name;
76  } elseif (!isset($this->parents[$parent])) {
77  $this->parents[$parent] = $this->env->loadTemplate($parent);
78  }
79 
80  return $this->parents[$parent];
81  }
82 
83  protected function doGetParent(array $context)
84  {
85  return false;
86  }
87 
88  public function isTraitable()
89  {
90  return true;
91  }
92 
103  public function displayParentBlock($name, array $context, array $blocks = array())
104  {
105  $name = (string) $name;
106 
107  if (isset($this->traits[$name])) {
108  $this->traits[$name][0]->displayBlock($name, $context, $blocks);
109  } elseif (false !== $parent = $this->getParent($context)) {
110  $parent->displayBlock($name, $context, $blocks);
111  } else {
112  throw new Twig_Error_Runtime(sprintf('The template has no parent and no traits defining the "%s" block', $name), -1, $this->getTemplateName());
113  }
114  }
115 
126  public function displayBlock($name, array $context, array $blocks = array())
127  {
128  $name = (string) $name;
129 
130  if (isset($blocks[$name])) {
131  $b = $blocks;
132  unset($b[$name]);
133  call_user_func($blocks[$name], $context, $b);
134  } elseif (isset($this->blocks[$name])) {
135  call_user_func($this->blocks[$name], $context, $blocks);
136  } elseif (false !== $parent = $this->getParent($context)) {
137  $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks));
138  }
139  }
140 
153  public function renderParentBlock($name, array $context, array $blocks = array())
154  {
155  ob_start();
156  $this->displayParentBlock($name, $context, $blocks);
157 
158  return ob_get_clean();
159  }
160 
173  public function renderBlock($name, array $context, array $blocks = array())
174  {
175  ob_start();
176  $this->displayBlock($name, $context, $blocks);
177 
178  return ob_get_clean();
179  }
180 
198  public function hasBlock($name)
199  {
200  return isset($this->blocks[(string) $name]);
201  }
202 
213  public function getBlockNames()
214  {
215  return array_keys($this->blocks);
216  }
217 
228  public function getBlocks()
229  {
230  return $this->blocks;
231  }
232 
236  public function display(array $context, array $blocks = array())
237  {
238  $this->displayWithErrorHandling($this->env->mergeGlobals($context), $blocks);
239  }
240 
244  public function render(array $context)
245  {
246  $level = ob_get_level();
247  ob_start();
248  try {
249  $this->display($context);
250  } catch (Exception $e) {
251  while (ob_get_level() > $level) {
252  ob_end_clean();
253  }
254 
255  throw $e;
256  }
257 
258  return ob_get_clean();
259  }
260 
261  protected function displayWithErrorHandling(array $context, array $blocks = array())
262  {
263  try {
264  $this->doDisplay($context, $blocks);
265  } catch (Twig_Error $e) {
266  if (!$e->getTemplateFile()) {
267  $e->setTemplateFile($this->getTemplateName());
268  }
269 
270  // this is mostly useful for Twig_Error_Loader exceptions
271  // see Twig_Error_Loader
272  if (false === $e->getTemplateLine()) {
273  $e->setTemplateLine(-1);
274  $e->guess();
275  }
276 
277  throw $e;
278  } catch (Exception $e) {
279  throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, null, $e);
280  }
281  }
282 
289  abstract protected function doDisplay(array $context, array $blocks = array());
290 
310  final protected function getContext($context, $item, $ignoreStrictCheck = false)
311  {
312  if (!array_key_exists($item, $context)) {
313  if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
314  return null;
315  }
316 
317  throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist', $item), -1, $this->getTemplateName());
318  }
319 
320  return $context[$item];
321  }
322 
337  protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
338  {
339  // array
340  if (Twig_TemplateInterface::METHOD_CALL !== $type) {
341  $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item;
342 
343  if ((is_array($object) && array_key_exists($arrayItem, $object))
344  || ($object instanceof ArrayAccess && isset($object[$arrayItem]))
345  ) {
346  if ($isDefinedTest) {
347  return true;
348  }
349 
350  return $object[$arrayItem];
351  }
352 
353  if (Twig_TemplateInterface::ARRAY_CALL === $type || !is_object($object)) {
354  if ($isDefinedTest) {
355  return false;
356  }
357 
358  if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
359  return null;
360  }
361 
362  if (is_object($object)) {
363  throw new Twig_Error_Runtime(sprintf('Key "%s" in object (with ArrayAccess) of type "%s" does not exist', $arrayItem, get_class($object)), -1, $this->getTemplateName());
364  } elseif (is_array($object)) {
365  throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))), -1, $this->getTemplateName());
367  throw new Twig_Error_Runtime(sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName());
368  } else {
369  throw new Twig_Error_Runtime(sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName());
370  }
371  }
372  }
373 
374  if (!is_object($object)) {
375  if ($isDefinedTest) {
376  return false;
377  }
378 
379  if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
380  return null;
381  }
382 
383  throw new Twig_Error_Runtime(sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s")', $item, gettype($object), $object), -1, $this->getTemplateName());
384  }
385 
386  $class = get_class($object);
387 
388  // object property
389  if (Twig_TemplateInterface::METHOD_CALL !== $type) {
390  if (isset($object->$item) || array_key_exists((string) $item, $object)) {
391  if ($isDefinedTest) {
392  return true;
393  }
394 
395  if ($this->env->hasExtension('sandbox')) {
396  $this->env->getExtension('sandbox')->checkPropertyAllowed($object, $item);
397  }
398 
399  return $object->$item;
400  }
401  }
402 
403  // object method
404  if (!isset(self::$cache[$class]['methods'])) {
405  self::$cache[$class]['methods'] = array_change_key_case(array_flip(get_class_methods($object)));
406  }
407 
408  $lcItem = strtolower($item);
409  if (isset(self::$cache[$class]['methods'][$lcItem])) {
410  $method = (string) $item;
411  } elseif (isset(self::$cache[$class]['methods']['get'.$lcItem])) {
412  $method = 'get'.$item;
413  } elseif (isset(self::$cache[$class]['methods']['is'.$lcItem])) {
414  $method = 'is'.$item;
415  } elseif (isset(self::$cache[$class]['methods']['__call'])) {
416  $method = (string) $item;
417  } else {
418  if ($isDefinedTest) {
419  return false;
420  }
421 
422  if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
423  return null;
424  }
425 
426  throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist', $item, get_class($object)), -1, $this->getTemplateName());
427  }
428 
429  if ($isDefinedTest) {
430  return true;
431  }
432 
433  if ($this->env->hasExtension('sandbox')) {
434  $this->env->getExtension('sandbox')->checkMethodAllowed($object, $method);
435  }
436 
437  $ret = call_user_func_array(array($object, $method), $arguments);
438 
439  // useful when calling a template method from a template
440  // this is not supported but unfortunately heavily used in the Symfony profiler
441  if ($object instanceof Twig_TemplateInterface) {
442  return $ret === '' ? '' : new Twig_Markup($ret, $this->env->getCharset());
443  }
444 
445  return $ret;
446  }
447 
451  public static function clearCache()
452  {
453  self::$cache = array();
454  }
455 }
getBlocks()
Returns all blocks.
Definition: Template.php:228
hasBlock($name)
Returns whether a block exists or not.
Definition: Template.php:198
if($rub=fetch_assoc($rub_query)) if(check_if_module_active('url_rewriting')) $class
Definition: index.php:68
getTemplateLine()
Gets the template line where the error occurred.
Definition: Error.php:116
displayParentBlock($name, array $context, array $blocks=array())
Displays a parent block.
Definition: Template.php:103
setTemplateLine($lineno)
Sets the template line where the error occurred.
Definition: Error.php:126
getAttribute($object, $item, array $arguments=array(), $type=Twig_TemplateInterface::ANY_CALL, $isDefinedTest=false, $ignoreStrictCheck=false)
Returns the attribute value for a given array/object.
Definition: Template.php:337
getTemplateFile()
Gets the filename where the error occurred.
Definition: Error.php:94
getEnvironment()
{Returns the bound environment for this template.Twig_Environment The current environment} ...
Definition: Template.php:50
Interface implemented by all compiled templates.
static $cache
Definition: Template.php:20
render(array $context)
{Renders the template with the given context and returns it as string.An array of parameters to pass ...
Definition: Template.php:244
Twig base exception.
Definition: Error.php:34
displayBlock($name, array $context, array $blocks=array())
Displays a block.
Definition: Template.php:126
__construct(Twig_Environment $env)
Constructor.
Definition: Template.php:33
doDisplay(array $context, array $blocks=array())
Auto-generated method to display the template with the given context.
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
Definition: chart-data.php:160
Marks a content as safe.
Definition: Markup.php:17
doGetParent(array $context)
Definition: Template.php:83
renderBlock($name, array $context, array $blocks=array())
Renders a block.
Definition: Template.php:173
Default base class for compiled templates.
Definition: Template.php:18
static clearCache()
This method is only useful when testing Twig.
Definition: Template.php:451
getContext($context, $item, $ignoreStrictCheck=false)
Returns a variable from the context.
Definition: Template.php:310
Stores the Twig configuration.
Definition: Environment.php:17
displayWithErrorHandling(array $context, array $blocks=array())
Definition: Template.php:261
getTemplateName()
Returns the template name.
getParent(array $context)
Returns the parent template.
Definition: Template.php:63
display(array $context, array $blocks=array())
{Displays the template with the given context.An array of parameters to pass to the template An array...
Definition: Template.php:236
Exception thrown when an error occurs at runtime.
Definition: Runtime.php:18
renderParentBlock($name, array $context, array $blocks=array())
Renders a parent block.
Definition: Template.php:153
setTemplateFile($filename)
Sets the filename where the error occurred.
Definition: Error.php:104
getBlockNames()
Returns all block names.
Definition: Template.php:213

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.