PEEL Shopping
Open source ecommerce : PEEL Shopping
Include.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 
19 {
20  public function __construct(Twig_Node_Expression $expr, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
21  {
22  parent::__construct(array('expr' => $expr, 'variables' => $variables), array('only' => (Boolean) $only, 'ignore_missing' => (Boolean) $ignoreMissing), $lineno, $tag);
23  }
24 
30  public function compile(Twig_Compiler $compiler)
31  {
32  $compiler->addDebugInfo($this);
33 
34  if ($this->getAttribute('ignore_missing')) {
35  $compiler
36  ->write("try {\n")
37  ->indent()
38  ;
39  }
40 
41  $this->addGetTemplate($compiler);
42 
43  $compiler->raw('->display(');
44 
45  $this->addTemplateArguments($compiler);
46 
47  $compiler->raw(");\n");
48 
49  if ($this->getAttribute('ignore_missing')) {
50  $compiler
51  ->outdent()
52  ->write("} catch (Twig_Error_Loader \$e) {\n")
53  ->indent()
54  ->write("// ignore missing template\n")
55  ->outdent()
56  ->write("}\n\n")
57  ;
58  }
59  }
60 
61  protected function addGetTemplate(Twig_Compiler $compiler)
62  {
63  if ($this->getNode('expr') instanceof Twig_Node_Expression_Constant) {
64  $compiler
65  ->write("\$this->env->loadTemplate(")
66  ->subcompile($this->getNode('expr'))
67  ->raw(")")
68  ;
69  } else {
70  $compiler
71  ->write("\$template = \$this->env->resolveTemplate(")
72  ->subcompile($this->getNode('expr'))
73  ->raw(");\n")
74  ->write('$template')
75  ;
76  }
77  }
78 
79  protected function addTemplateArguments(Twig_Compiler $compiler)
80  {
81  if (false === $this->getAttribute('only')) {
82  if (null === $this->getNode('variables')) {
83  $compiler->raw('$context');
84  } else {
85  $compiler
86  ->raw('array_merge($context, ')
87  ->subcompile($this->getNode('variables'))
88  ->raw(')')
89  ;
90  }
91  } else {
92  if (null === $this->getNode('variables')) {
93  $compiler->raw('array()');
94  } else {
95  $compiler->subcompile($this->getNode('variables'));
96  }
97  }
98  }
99 }
Compiles a node to PHP code.
Definition: Compiler.php:18
outdent($step=1)
Outdents the generated code.
Definition: Compiler.php:256
Represents an include node.
Definition: Include.php:18
Represents a node in the AST.
Definition: Node.php:18
compile(Twig_Compiler $compiler)
Compiles the node to PHP.
Definition: Include.php:30
getAttribute($name)
Gets an attribute.
Definition: Node.php:138
$lineno
Definition: Node.php:22
addDebugInfo(Twig_NodeInterface $node)
Adds debugging information.
Definition: Compiler.php:207
Abstract class for all nodes that represents an expression.
Definition: Expression.php:18
addGetTemplate(Twig_Compiler $compiler)
Definition: Include.php:61
addTemplateArguments(Twig_Compiler $compiler)
Definition: Include.php:79
subcompile(Twig_NodeInterface $node, $raw=true)
Definition: Compiler.php:91
raw($string)
Adds a raw string to the compiled code.
Definition: Compiler.php:109
Represents a displayable node in the AST.
write()
Writes a string to the compiled code by adding indentation.
Definition: Compiler.php:121
__construct(Twig_Node_Expression $expr, Twig_Node_Expression $variables=null, $only=false, $ignoreMissing=false, $lineno, $tag=null)
Definition: Include.php:20
getNode($name)
Gets a node by name.
Definition: Node.php:187

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