diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-02 22:43:56 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-02 22:43:56 +0200 |
commit | 8069e235fd2971675ee5fc05026ffa9bce5cbbb7 (patch) | |
tree | 872eaed228b5e1b031c21770fba1701106a52a39 /inc/3rdparty/Twig/Node/Include.php | |
parent | 45161a64026cec35fcf07659508143a6f55ddf57 (diff) | |
download | wallabag-8069e235fd2971675ee5fc05026ffa9bce5cbbb7.tar.gz wallabag-8069e235fd2971675ee5fc05026ffa9bce5cbbb7.tar.zst wallabag-8069e235fd2971675ee5fc05026ffa9bce5cbbb7.zip |
move Twig in 3rdparty
Diffstat (limited to 'inc/3rdparty/Twig/Node/Include.php')
-rw-r--r-- | inc/3rdparty/Twig/Node/Include.php | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/inc/3rdparty/Twig/Node/Include.php b/inc/3rdparty/Twig/Node/Include.php new file mode 100644 index 00000000..ed4a3751 --- /dev/null +++ b/inc/3rdparty/Twig/Node/Include.php | |||
@@ -0,0 +1,99 @@ | |||
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 | |||
13 | /** | ||
14 | * Represents an include node. | ||
15 | * | ||
16 | * @author Fabien Potencier <fabien@symfony.com> | ||
17 | */ | ||
18 | class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface | ||
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 | |||
25 | /** | ||
26 | * Compiles the node to PHP. | ||
27 | * | ||
28 | * @param Twig_Compiler A Twig_Compiler instance | ||
29 | */ | ||
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 | } | ||