8000 Merge branch '2.0' · mshtukin/symfony@f8f31a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit f8f31a2

Browse files
committed
Merge branch '2.0'
* 2.0: [Twig] made code compatible with Twig 1.5
2 parents b498138 + adea589 commit f8f31a2

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/Symfony/Bridge/Twig/Node/TransNode.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,24 @@ protected functio 8000 n compileString(\Twig_NodeInterface $body, \Twig_Node_Expressio
8989
return array($body, $vars);
9090
}
9191

92-
$current = array();
93-
foreach ($vars as $name => $var) {
94-
$current[$name] = true;
95-
}
96-
9792
preg_match_all('/(?<!%)%([^%]+)%/', $msg, $matches);
98-
foreach ($matches[1] as $var) {
99-
if (!isset($current['%'.$var.'%'])) {
100-
$vars->setNode('%'.$var.'%', new \Twig_Node_Expression_Name($var, $body->getLine()));
93+
94+
if (version_compare(\Twig_Environment::VERSION, '1.5', '>=')) {
95+
foreach ($matches[1] as $var) {
96+
$key = new \Twig_Node_Expression_Constant('%'.$var.'%', $body->getLine());
97+
if (!$vars->hasElement($key)) {
98+
$vars->addElement(new \Twig_Node_Expression_Name($var, $body->getLine()), $key);
99+
}
100+
}
101+
} else {
102+
$current = array();
103+
foreach ($vars as $name => $var) {
104+
$current[$name] = true;
105+
}
106+
foreach ($matches[1] as $var) {
107+
if (!isset($current['%'.$var.'%'])) {
108+
$vars->setNode('%'.$var.'%', new \Twig_Node_Expression_Name($var, $body->getLine()));
109+
}
101110
}
102111
}
103112

0 commit comments

Comments
 (0)
0