diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-03 19:26:54 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-03 19:26:54 +0200 |
commit | 4f5b44bd3bd490309eb2ba7b44df4769816ba729 (patch) | |
tree | 6cefe170dfe0a5a361cb1e2d1fc4d580a3316d02 /inc/3rdparty/Twig/Extensions/Node | |
parent | 2b840e0cfb63a453bea67a98541f3df9c273c5f5 (diff) | |
download | wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.gz wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.tar.zst wallabag-4f5b44bd3bd490309eb2ba7b44df4769816ba729.zip |
twig implementation
Diffstat (limited to 'inc/3rdparty/Twig/Extensions/Node')
-rw-r--r-- | inc/3rdparty/Twig/Extensions/Node/Debug.php | 69 | ||||
-rw-r--r-- | inc/3rdparty/Twig/Extensions/Node/Trans.php | 133 |
2 files changed, 0 insertions, 202 deletions
diff --git a/inc/3rdparty/Twig/Extensions/Node/Debug.php b/inc/3rdparty/Twig/Extensions/Node/Debug.php deleted file mode 100644 index 7d01bbe5..00000000 --- a/inc/3rdparty/Twig/Extensions/Node/Debug.php +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of Twig. | ||
5 | * | ||
6 | * (c) 2010 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 | |||
12 | /** | ||
13 | * Represents a debug node. | ||
14 | * | ||
15 | * @package twig | ||
16 | * @subpackage Twig-extensions | ||
17 | * @author Fabien Potencier <fabien.potencier@symfony-project.com> | ||
18 | * @version SVN: $Id$ | ||
19 | */ | ||
20 | class Twig_Extensions_Node_Debug extends Twig_Node | ||
21 | { | ||
22 | public function __construct(Twig_Node_Expression $expr = null, $lineno, $tag = null) | ||
23 | { | ||
24 | parent::__construct(array('expr' => $expr), array(), $lineno, $tag); | ||
25 | } | ||
26 | |||
27 | /** | ||
28 | * Compiles the node to PHP. | ||
29 | * | ||
30 | * @param Twig_Compiler A Twig_Compiler instance | ||
31 | */ | ||
32 | public function compile(Twig_Compiler $compiler) | ||
33 | { | ||
34 | $compiler->addDebugInfo($this); | ||
35 | |||
36 | $compiler | ||
37 | ->write("if (\$this->env->isDebug()) {\n") | ||
38 | ->indent() | ||
39 | ; | ||
40 | |||
41 | if (null === $this->getNode('expr')) { | ||
42 | // remove embedded templates (macros) from the context | ||
43 | $compiler | ||
44 | ->write("\$vars = array();\n") | ||
45 | ->write("foreach (\$context as \$key => \$value) {\n") | ||
46 | ->indent() | ||
47 | ->write("if (!\$value instanceof Twig_Template) {\n") | ||
48 | ->indent() | ||
49 | ->write("\$vars[\$key] = \$value;\n") | ||
50 | ->outdent() | ||
51 | ->write("}\n") | ||
52 | ->outdent() | ||
53 | ->write("}\n") | ||
54 | ->write("var_dump(\$vars);\n") | ||
55 | ; | ||
56 | } else { | ||
57 | $compiler | ||
58 | ->write("var_dump(") | ||
59 | ->subcompile($this->getNode('expr')) | ||
60 | ->raw(");\n") | ||
61 | ; | ||
62 | } | ||
63 | |||
64 | $compiler | ||
65 | ->outdent() | ||
66 | ->write("}\n") | ||
67 | ; | ||
68 | } | ||
69 | } | ||
diff --git a/inc/3rdparty/Twig/Extensions/Node/Trans.php b/inc/3rdparty/Twig/Extensions/Node/Trans.php deleted file mode 100644 index d12564a7..00000000 --- a/inc/3rdparty/Twig/Extensions/Node/Trans.php +++ /dev/null | |||
@@ -1,133 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of Twig. | ||
5 | * | ||
6 | * (c) 2010 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 | |||
12 | /** | ||
13 | * Represents a trans node. | ||
14 | * | ||
15 | * @package twig | ||
16 | * @author Fabien Potencier <fabien.potencier@symfony-project.com> | ||
17 | */ | ||
18 | class Twig_Extensions_Node_Trans extends Twig_Node | ||
19 | { | ||
20 | public function __construct(Twig_NodeInterface $body, Twig_NodeInterface $plural = null, Twig_Node_Expression $count = null, $lineno, $tag = null) | ||
21 | { | ||
22 | parent::__construct(array('count' => $count, 'body' => $body, 'plural' => $plural), array(), $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 | list($msg, $vars) = $this->compileString($this->getNode('body')); | ||
35 | |||
36 | if (null !== $this->getNode('plural')) { | ||
37 | list($msg1, $vars1) = $this->compileString($this->getNode('plural')); | ||
38 | |||
39 | $vars = array_merge($vars, $vars1); | ||
40 | } | ||
41 | |||
42 | $function = null === $this->getNode('plural') ? 'gettext' : 'ngettext'; | ||
43 | |||
44 | if ($vars) { | ||
45 | $compiler | ||
46 | ->write('echo strtr('.$function.'(') | ||
47 | ->subcompile($msg) | ||
48 | ; | ||
49 | |||
50 | if (null !== $this->getNode('plural')) { | ||
51 | $compiler | ||
52 | ->raw(', ') | ||
53 | ->subcompile($msg1) | ||
54 | ->raw(', abs(') | ||
55 | ->subcompile($this->getNode('count')) | ||
56 | ->raw(')') | ||
57 | ; | ||
58 | } | ||
59 | |||
60 | $compiler->raw('), array('); | ||
61 | |||
62 | foreach ($vars as $var) { | ||
63 | if ('count' === $var->getAttribute('name')) { | ||
64 | $compiler | ||
65 | ->string('%count%') | ||
66 | ->raw(' => abs(') | ||
67 | ->subcompile($this->getNode('count')) | ||
68 | ->raw('), ') | ||
69 | ; | ||
70 | } else { | ||
71 | $compiler | ||
72 | ->string('%'.$var->getAttribute('name').'%') | ||
73 | ->raw(' => ') | ||
74 | ->subcompile($var) | ||
75 | ->raw(', ') | ||
76 | ; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | $compiler->raw("));\n"); | ||
81 | } else { | ||
82 | $compiler | ||
83 | ->write('echo '.$function.'(') | ||
84 | ->subcompile($msg) | ||
85 | ; | ||
86 | |||
87 | if (null !== $this->getNode('plural')) { | ||
88 | $compiler | ||
89 | ->raw(', ') | ||
90 | ->subcompile($msg1) | ||
91 | ->raw(', abs(') | ||
92 | ->subcompile($this->getNode('count')) | ||
93 | ->raw(')') | ||
94 | ; | ||
95 | } | ||
96 | |||
97 | $compiler->raw(");\n"); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | protected function compileString(Twig_NodeInterface $body) | ||
102 | { | ||
103 | if ($body instanceof Twig_Node_Expression_Name || $body instanceof Twig_Node_Expression_Constant || $body instanceof Twig_Node_Expression_TempName) { | ||
104 | return array($body, array()); | ||
105 | } | ||
106 | |||
107 | $vars = array(); | ||
108 | if (count($body)) { | ||
109 | $msg = ''; | ||
110 | |||
111 | foreach ($body as $node) { | ||
112 | if (get_class($node) === 'Twig_Node' && $node->getNode(0) instanceof Twig_Node_SetTemp) { | ||
113 | $node = $node->getNode(1); | ||
114 | } | ||
115 | |||
116 | if ($node instanceof Twig_Node_Print) { | ||
117 | $n = $node->getNode('expr'); | ||
118 | while ($n instanceof Twig_Node_Expression_Filter) { | ||
119 | $n = $n->getNode('node'); | ||
120 | } | ||
121 | $msg .= sprintf('%%%s%%', $n->getAttribute('name')); | ||
122 | $vars[] = new Twig_Node_Expression_Name($n->getAttribute('name'), $n->getLine()); | ||
123 | } else { | ||
124 | $msg .= $node->getAttribute('data'); | ||
125 | } | ||
126 | } | ||
127 | } else { | ||
128 | $msg = $body->getAttribute('data'); | ||
129 | } | ||
130 | |||
131 | return array(new Twig_Node(array(new Twig_Node_Expression_Constant(trim($msg), $body->getLine()))), $vars); | ||
132 | } | ||
133 | } | ||