aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node')
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/FormEnctypeNode.php31
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/FormThemeNode.php40
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/RenderBlockNode.php42
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php106
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php33
-rw-r--r--vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/TransNode.php119
6 files changed, 371 insertions, 0 deletions
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/FormEnctypeNode.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/FormEnctypeNode.php
new file mode 100644
index 00000000..93bce1b9
--- /dev/null
+++ b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/FormEnctypeNode.php
@@ -0,0 +1,31 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Bridge\Twig\Node;
13
14/**
15 * @author Bernhard Schussek <bschussek@gmail.com>
16 *
17 * @deprecated Deprecated since version 2.3, to be removed in 3.0. Use
18 * the helper "form_start()" instead.
19 */
20class FormEnctypeNode extends SearchAndRenderBlockNode
21{
22 public function compile(\Twig_Compiler $compiler)
23 {
24 parent::compile($compiler);
25
26 $compiler->raw(";\n");
27
28 // Uncomment this as soon as the deprecation note should be shown
29 // $compiler->write('trigger_error(\'The helper form_enctype(form) is deprecated since version 2.3 and will be removed in 3.0. Use form_start(form) instead.\', E_USER_DEPRECATED)');
30 }
31}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/FormThemeNode.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/FormThemeNode.php
new file mode 100644
index 00000000..329ab86f
--- /dev/null
+++ b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/FormThemeNode.php
@@ -0,0 +1,40 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Bridge\Twig\Node;
13
14/**
15 * @author Fabien Potencier <fabien@symfony.com>
16 */
17class FormThemeNode extends \Twig_Node
18{
19 public function __construct(\Twig_NodeInterface $form, \Twig_NodeInterface $resources, $lineno, $tag = null)
20 {
21 parent::__construct(array('form' => $form, 'resources' => $resources), array(), $lineno, $tag);
22 }
23
24 /**
25 * Compiles the node to PHP.
26 *
27 * @param \Twig_Compiler $compiler A Twig_Compiler instance
28 */
29 public function compile(\Twig_Compiler $compiler)
30 {
31 $compiler
32 ->addDebugInfo($this)
33 ->write('$this->env->getExtension(\'form\')->renderer->setTheme(')
34 ->subcompile($this->getNode('form'))
35 ->raw(', ')
36 ->subcompile($this->getNode('resources'))
37 ->raw(");\n");
38 ;
39 }
40}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/RenderBlockNode.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/RenderBlockNode.php
new file mode 100644
index 00000000..822a2727
--- /dev/null
+++ b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/RenderBlockNode.php
@@ -0,0 +1,42 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Bridge\Twig\Node;
13
14/**
15 * Compiles a call to {@link FormRendererInterface::renderBlock()}.
16 *
17 * The function name is used as block name. For example, if the function name
18 * is "foo", the block "foo" will be rendered.
19 *
20 * @author Bernhard Schussek <bschussek@gmail.com>
21 */
22class RenderBlockNode extends \Twig_Node_Expression_Function
23{
24 public function compile(\Twig_Compiler $compiler)
25 {
26 $compiler->addDebugInfo($this);
27 $arguments = iterator_to_array($this->getNode('arguments'));
28 $compiler->write('$this->env->getExtension(\'form\')->renderer->renderBlock(');
29
30 if (isset($arguments[0])) {
31 $compiler->subcompile($arguments[0]);
32 $compiler->raw(', \'' . $this->getAttribute('name') . '\'');
33
34 if (isset($arguments[1])) {
35 $compiler->raw(', ');
36 $compiler->subcompile($arguments[1]);
37 }
38 }
39
40 $compiler->raw(')');
41 }
42}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php
new file mode 100644
index 00000000..630e2638
--- /dev/null
+++ b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/SearchAndRenderBlockNode.php
@@ -0,0 +1,106 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Bridge\Twig\Node;
13
14/**
15 * @author Bernhard Schussek <bschussek@gmail.com>
16 */
17class SearchAndRenderBlockNode extends \Twig_Node_Expression_Function
18{
19 public function compile(\Twig_Compiler $compiler)
20 {
21 $compiler->addDebugInfo($this);
22 $compiler->raw('$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(');
23
24 preg_match('/_([^_]+)$/', $this->getAttribute('name'), $matches);
25
26 $label = null;
27 $arguments = iterator_to_array($this->getNode('arguments'));
28 $blockNameSuffix = $matches[1];
29
30 if (isset($arguments[0])) {
31 $compiler->subcompile($arguments[0]);
32 $compiler->raw(', \''.$blockNameSuffix.'\'');
33
34 if (isset($arguments[1])) {
35 if ('label' === $blockNameSuffix) {
36 // The "label" function expects the label in the second and
37 // the variables in the third argument
38 $label = $arguments[1];
39 $variables = isset($arguments[2]) ? $arguments[2] : null;
40 $lineno = $label->getLine();
41
42 if ($label instanceof \Twig_Node_Expression_Constant) {
43 // If the label argument is given as a constant, we can either
44 // strip it away if it is empty, or integrate it into the array
45 // of variables at compile time.
46 $labelIsExpression = false;
47
48 // Only insert the label into the array if it is not empty
49 if (!twig_test_empty($label->getAttribute('value'))) {
50 $originalVariables = $variables;
51 $variables = new \Twig_Node_Expression_Array(array(), $lineno);
52 $labelKey = new \Twig_Node_Expression_Constant('label', $lineno);
53
54 if (null !== $originalVariables) {
55 foreach ($originalVariables->getKeyValuePairs() as $pair) {
56 // Don't copy the original label attribute over if it exists
57 if ((string) $labelKey !== (string) $pair['key']) {
58 $variables->addElement($pair['value'], $pair['key']);
59 }
60 }
61 }
62
63 // Insert the label argument into the array
64 $variables->addElement($label, $labelKey);
65 }
66 } else {
67 // The label argument is not a constant, but some kind of
68 // expression. This expression needs to be evaluated at runtime.
69 // Depending on the result (whether it is null or not), the
70 // label in the arguments should take precedence over the label
71 // in the attributes or not.
72 $labelIsExpression = true;
73 }
74 } else {
75 // All other functions than "label" expect the variables
76 // in the second argument
77 $label = null;
78 $variables = $arguments[1];
79 $labelIsExpression = false;
80 }
81
82 if (null !== $variables || $labelIsExpression) {
83 $compiler->raw(', ');
84
85 if (null !== $variables) {
86 $compiler->subcompile($variables);
87 }
88
89 if ($labelIsExpression) {
90 if (null !== $variables) {
91 $compiler->raw(' + ');
92 }
93
94 // Check at runtime whether the label is empty.
95 // If not, add it to the array at runtime.
96 $compiler->raw('(twig_test_empty($_label_ = ');
97 $compiler->subcompile($label);
98 $compiler->raw(') ? array() : array("label" => $_label_))');
99 }
100 }
101 }
102 }
103
104 $compiler->raw(")");
105 }
106}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php
new file mode 100644
index 00000000..adee71ff
--- /dev/null
+++ b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php
@@ -0,0 +1,33 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Bridge\Twig\Node;
13
14/**
15 * @author Fabien Potencier <fabien@symfony.com>
16 */
17class TransDefaultDomainNode extends \Twig_Node
18{
19 public function __construct(\Twig_Node_Expression $expr, $lineno = 0, $tag = null)
20 {
21 parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
22 }
23
24 /**
25 * Compiles the node to PHP.
26 *
27 * @param \Twig_Compiler $compiler A Twig_Compiler instance
28 */
29 public function compile(\Twig_Compiler $compiler)
30 {
31 // noop as this node is just a marker for TranslationDefaultDomainNodeVisitor
32 }
33}
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/TransNode.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/TransNode.php
new file mode 100644
index 00000000..a68c101a
--- /dev/null
+++ b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Node/TransNode.php
@@ -0,0 +1,119 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Bridge\Twig\Node;
13
14/**
15 * @author Fabien Potencier <fabien@symfony.com>
16 */
17class TransNode extends \Twig_Node
18{
19 public function __construct(\Twig_NodeInterface $body, \Twig_NodeInterface $domain = null, \Twig_Node_Expression $count = null, \Twig_Node_Expression $vars = null, \Twig_Node_Expression $locale = null, $lineno = 0, $tag = null)
20 {
21 parent::__construct(array('count' => $count, 'body' => $body, 'domain' => $domain, 'vars' => $vars, 'locale' => $locale), array(), $lineno, $tag);
22 }
23
24 /**
25 * Compiles the node to PHP.
26 *
27 * @param \Twig_Compiler $compiler A Twig_Compiler instance
28 */
29 public function compile(\Twig_Compiler $compiler)
30 {
31 $compiler->addDebugInfo($this);
32
33 $vars = $this->getNode('vars');
34 $defaults = new \Twig_Node_Expression_Array(array(), -1);
35 if ($vars instanceof \Twig_Node_Expression_Array) {
36 $defaults = $this->getNode('vars');
37 $vars = null;
38 }
39 list($msg, $defaults) = $this->compileString($this->getNode('body'), $defaults);
40
41 $method = null === $this->getNode('count') ? 'trans' : 'transChoice';
42
43 $compiler
44 ->write('echo $this->env->getExtension(\'translator\')->getTranslator()->'.$method.'(')
45 ->subcompile($msg)
46 ;
47
48 $compiler->raw(', ');
49
50 if (null !== $this->getNode('count')) {
51 $compiler
52 ->subcompile($this->getNode('count'))
53 ->raw(', ')
54 ;
55 }
56
57 if (null !== $vars) {
58 $compiler
59 ->raw('array_merge(')
60 ->subcompile($defaults)
61 ->raw(', ')
62 ->subcompile($this->getNode('vars'))
63 ->raw(')')
64 ;
65 } else {
66 $compiler->subcompile($defaults);
67 }
68
69 $compiler->raw(', ');
70
71 if (null === $this->getNode('domain')) {
72 $compiler->repr('messages');
73 } else {
74 $compiler->subcompile($this->getNode('domain'));
75 }
76
77 if (null !== $this->getNode('locale')) {
78 $compiler
79 ->raw(', ')
80 ->subcompile($this->getNode('locale'))
81 ;
82 }
83 $compiler->raw(");\n");
84 }
85
86 protected function compileString(\Twig_NodeInterface $body, \Twig_Node_Expression_Array $vars)
87 {
88 if ($body instanceof \Twig_Node_Expression_Constant) {
89 $msg = $body->getAttribute('value');
90 } elseif ($body instanceof \Twig_Node_Text) {
91 $msg = $body->getAttribute('data');
92 } else {
93 return array($body, $vars);
94 }
95
96 preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
97
98 if (version_compare(\Twig_Environment::VERSION, '1.5', '>=')) {
99 foreach ($matches[1] as $var) {
100 $key = new \Twig_Node_Expression_Constant('%'.$var.'%', $body->getLine());
101 if (!$vars->hasElement($key)) {
102 $vars->addElement(new \Twig_Node_Expression_Name($var, $body->getLine()), $key);
103 }
104 }
105 } else {
106 $current = array();
107 foreach ($vars as $name => $var) {
108 $current[$name] = true;
109 }
110 foreach ($matches[1] as $var) {
111 if (!isset($current['%'.$var.'%'])) {
112 $vars->setNode('%'.$var.'%', new \Twig_Node_Expression_Name($var, $body->getLine()));
113 }
114 }
115 }
116
117 return array(new \Twig_Node_Expression_Constant(str_replace('%%', '%', trim($msg)), $body->getLine()), $vars);
118 }
119}