From 29b020eb2f029d77ce0d055cf9212b33b787a50e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 2 Oct 2010 08:23:54 +0200 Subject: [PATCH] changed the way to access nodes and attributes from a node Before: Nodes were accessed via node properties ($node->body) Attributes were accessed via node array access ($node['name']) After: Nodes are accessed via getNode(), setNode(), ... ($node->getNode('body')) Attributes are accessed via getAttribute(), setAttribute(), ... ($node->getAttribute('name')) The change was necessary because of side-effects. This is one more time the demonstration that being explicit is always better than magic ;) --- CHANGELOG | 3 ++ doc/04-Extending-Twig.markdown | 4 +- lib/Twig/Node.php | 23 ++++++-------- lib/Twig/Node/AutoEscape.php | 2 +- lib/Twig/Node/Block.php | 4 +- lib/Twig/Node/BlockReference.php | 2 +- lib/Twig/Node/Expression/AssignName.php | 2 +- lib/Twig/Node/Expression/Binary.php | 4 +- lib/Twig/Node/Expression/Compare.php | 16 +++++----- lib/Twig/Node/Expression/Conditional.php | 6 ++-- lib/Twig/Node/Expression/Constant.php | 2 +- lib/Twig/Node/Expression/ExtensionReference.php | 2 +- lib/Twig/Node/Expression/Filter.php | 22 +++++++------- lib/Twig/Node/Expression/GetAttr.php | 8 ++-- lib/Twig/Node/Expression/Name.php | 8 ++-- lib/Twig/Node/Expression/Test.php | 14 ++++---- lib/Twig/Node/Expression/Unary.php | 2 +- lib/Twig/Node/For.php | 22 +++++++------- lib/Twig/Node/If.php | 10 +++--- lib/Twig/Node/Import.php | 6 ++-- lib/Twig/Node/Include.php | 10 +++--- lib/Twig/Node/Macro.php | 14 ++++---- lib/Twig/Node/Module.php | 28 ++++++++-------- lib/Twig/Node/Parent.php | 2 +- lib/Twig/Node/Print.php | 2 +- lib/Twig/Node/Sandbox.php | 2 +- lib/Twig/Node/SandboxedModule.php | 6 ++-- lib/Twig/Node/SandboxedPrint.php | 6 ++-- lib/Twig/Node/Set.php | 20 ++++++------ lib/Twig/Node/Text.php | 2 +- lib/Twig/Node/Trans.php | 32 ++++++++++---------- lib/Twig/NodeTraverser.php | 4 +- lib/Twig/NodeVisitor/Escaper.php | 20 ++++++------ lib/Twig/NodeVisitor/Sandbox.php | 6 ++-- lib/Twig/Parser.php | 2 +- lib/Twig/TokenParser/For.php | 6 ++-- test/Twig/Tests/Node/AutoEscapeTest.php | 4 +- test/Twig/Tests/Node/BlockReferenceTest.php | 2 +- test/Twig/Tests/Node/BlockTest.php | 4 +- test/Twig/Tests/Node/Expression/ArrayTest.php | 2 +- test/Twig/Tests/Node/Expression/AssignNameTest.php | 2 +- test/Twig/Tests/Node/Expression/Binary/AddTest.php | 4 +- test/Twig/Tests/Node/Expression/Binary/AndTest.php | 4 +- .../Tests/Node/Expression/Binary/ConcatTest.php | 4 +- test/Twig/Tests/Node/Expression/Binary/DivTest.php | 4 +- .../Tests/Node/Expression/Binary/FloorDivTest.php | 4 +- test/Twig/Tests/Node/Expression/Binary/ModTest.php | 4 +- test/Twig/Tests/Node/Expression/Binary/MulTest.php | 4 +- test/Twig/Tests/Node/Expression/Binary/OrTest.php | 4 +- test/Twig/Tests/Node/Expression/Binary/SubTest.php | 4 +- test/Twig/Tests/Node/Expression/CompareTest.php | 4 +- .../Twig/Tests/Node/Expression/ConditionalTest.php | 6 ++-- test/Twig/Tests/Node/Expression/ConstantTest.php | 2 +- test/Twig/Tests/Node/Expression/FilterTest.php | 10 +++--- test/Twig/Tests/Node/Expression/GetAttrTest.php | 8 ++-- test/Twig/Tests/Node/Expression/NameTest.php | 2 +- test/Twig/Tests/Node/Expression/Unary/NegTest.php | 2 +- test/Twig/Tests/Node/Expression/Unary/NotTest.php | 2 +- test/Twig/Tests/Node/Expression/Unary/PosTest.php | 2 +- test/Twig/Tests/Node/ForTest.php | 14 ++++---- test/Twig/Tests/Node/IfTest.php | 6 ++-- test/Twig/Tests/Node/ImportTest.php | 4 +- test/Twig/Tests/Node/IncludeTest.php | 6 ++-- test/Twig/Tests/Node/MacroTest.php | 6 ++-- test/Twig/Tests/Node/ModuleTest.php | 10 +++--- test/Twig/Tests/Node/ParentTest.php | 2 +- test/Twig/Tests/Node/PrintTest.php | 2 +- test/Twig/Tests/Node/SandboxTest.php | 2 +- test/Twig/Tests/Node/SandboxedModuleTest.php | 10 +++--- test/Twig/Tests/Node/SandboxedPrintTest.php | 2 +- test/Twig/Tests/Node/SetTest.php | 6 ++-- test/Twig/Tests/Node/TextTest.php | 2 +- test/Twig/Tests/Node/TransTest.php | 6 ++-- 73 files changed, 245 insertions(+), 245 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 47143dc..3dffe26 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,9 @@ Backward incompatibilities: * the odd and even filters are now tests: {{ foo|odd }} must now be written {{ foo is odd }} * the "safe" filter has been renamed to "raw" + * in Node classes, + sub-nodes are now accessed via getNode() (instead of property access) + attributes via getAttribute() (instead of array access) * the implementation of template inheritance has been rewritten (blocks can now be called individually and still work with inheritance) diff --git a/doc/04-Extending-Twig.markdown b/doc/04-Extending-Twig.markdown index bfe5378..c1222e4 100644 --- a/doc/04-Extending-Twig.markdown +++ b/doc/04-Extending-Twig.markdown @@ -516,8 +516,8 @@ The `Project_Set_Node` class itself is rather simple: { $compiler ->addDebugInfo($this) - ->write('$context[\''.$this['name'].'\'] = ') - ->subcompile($this->value) + ->write('$context[\''.$this->getAttribute('name').'\'] = ') + ->subcompile($this->getNode('value')) ->raw(";\n") ; } diff --git a/lib/Twig/Node.php b/lib/Twig/Node.php index 58ce258..4d6b125 100644 --- a/lib/Twig/Node.php +++ b/lib/Twig/Node.php @@ -17,7 +17,7 @@ * @author Fabien Potencier * @version SVN: $Id$ */ -class Twig_Node implements Twig_NodeInterface, ArrayAccess, Countable, IteratorAggregate +class Twig_Node implements Twig_NodeInterface, Countable, IteratorAggregate { protected $nodes; protected $attributes; @@ -37,10 +37,7 @@ class Twig_Node implements Twig_NodeInterface, ArrayAccess, Countable, IteratorA */ public function __construct(array $nodes = array(), array $attributes = array(), $lineno = 0, $tag = null) { - $this->nodes = array(); - foreach ($nodes as $name => $node) { - $this->$name = $node; - } + $this->nodes = $nodes; $this->attributes = $attributes; $this->lineno = $lineno; $this->tag = $tag; @@ -128,7 +125,7 @@ class Twig_Node implements Twig_NodeInterface, ArrayAccess, Countable, IteratorA * * @return Boolean true if the attribute is defined, false otherwise */ - public function offsetExists($name) + public function hasAttribute($name) { return array_key_exists($name, $this->attributes); } @@ -140,7 +137,7 @@ class Twig_Node implements Twig_NodeInterface, ArrayAccess, Countable, IteratorA * * @return mixed The attribute value */ - public function offsetGet($name) + public function getAttribute($name) { if (!array_key_exists($name, $this->attributes)) { throw new InvalidArgumentException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, get_class($this))); @@ -155,7 +152,7 @@ class Twig_Node implements Twig_NodeInterface, ArrayAccess, Countable, IteratorA * @param string The attribute name * @param mixed The attribute value */ - public function offsetSet($name, $value) + public function setAttribute($name, $value) { $this->attributes[$name] = $value; } @@ -165,7 +162,7 @@ class Twig_Node implements Twig_NodeInterface, ArrayAccess, Countable, IteratorA * * @param string The attribute name */ - public function offsetUnset($name) + public function removeAttribute($name) { unset($this->attributes[$name]); } @@ -177,7 +174,7 @@ class Twig_Node implements Twig_NodeInterface, ArrayAccess, Countable, IteratorA * * @return Boolean true if the node with the given name exists, false otherwise */ - public function __isset($name) + public function hasNode($name) { return array_key_exists($name, $this->nodes); } @@ -189,7 +186,7 @@ class Twig_Node implements Twig_NodeInterface, ArrayAccess, Countable, IteratorA * * @return Twig_Node A Twig_Node instance */ - public function __get($name) + public function getNode($name) { if (!array_key_exists($name, $this->nodes)) { throw new InvalidArgumentException(sprintf('Node "%s" does not exist for Node "%s".', $name, get_class($this))); @@ -204,7 +201,7 @@ class Twig_Node implements Twig_NodeInterface, ArrayAccess, Countable, IteratorA * @param string The node name * @param Twig_Node A Twig_Node instance */ - public function __set($name, $node = null) + public function setNode($name, $node = null) { $this->nodes[$name] = $node; } @@ -214,7 +211,7 @@ class Twig_Node implements Twig_NodeInterface, ArrayAccess, Countable, IteratorA * * @param string The node name */ - public function __unset($name) + public function removeNode($name) { unset($this->nodes[$name]); } diff --git a/lib/Twig/Node/AutoEscape.php b/lib/Twig/Node/AutoEscape.php index a238e9b..8c20a13 100644 --- a/lib/Twig/Node/AutoEscape.php +++ b/lib/Twig/Node/AutoEscape.php @@ -36,6 +36,6 @@ class Twig_Node_AutoEscape extends Twig_Node */ public function compile($compiler) { - $compiler->subcompile($this->body); + $compiler->subcompile($this->getNode('body')); } } diff --git a/lib/Twig/Node/Block.php b/lib/Twig/Node/Block.php index d73e98d..321903d 100644 --- a/lib/Twig/Node/Block.php +++ b/lib/Twig/Node/Block.php @@ -33,12 +33,12 @@ class Twig_Node_Block extends Twig_Node { $compiler ->addDebugInfo($this) - ->write(sprintf("public function block_%s(\$context, array \$blocks = array())\n", $this['name']), "{\n") + ->write(sprintf("public function block_%s(\$context, array \$blocks = array())\n", $this->getAttribute('name')), "{\n") ->indent() ; $compiler - ->subcompile($this->body) + ->subcompile($this->getNode('body')) ->outdent() ->write("}\n\n") ; diff --git a/lib/Twig/Node/BlockReference.php b/lib/Twig/Node/BlockReference.php index 1314f7b..7623947 100644 --- a/lib/Twig/Node/BlockReference.php +++ b/lib/Twig/Node/BlockReference.php @@ -33,7 +33,7 @@ class Twig_Node_BlockReference extends Twig_Node { $compiler ->addDebugInfo($this) - ->write(sprintf("\$this->getBlock('%s', \$context, \$blocks);\n", $this['name'])) + ->write(sprintf("\$this->getBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name'))) ; } } diff --git a/lib/Twig/Node/Expression/AssignName.php b/lib/Twig/Node/Expression/AssignName.php index bf14fa4..e5b0d71 100644 --- a/lib/Twig/Node/Expression/AssignName.php +++ b/lib/Twig/Node/Expression/AssignName.php @@ -19,6 +19,6 @@ class Twig_Node_Expression_AssignName extends Twig_Node_Expression_Name */ public function compile($compiler) { - $compiler->raw(sprintf('$context[\'%s\']', $this['name'])); + $compiler->raw(sprintf('$context[\'%s\']', $this->getAttribute('name'))); } } diff --git a/lib/Twig/Node/Expression/Binary.php b/lib/Twig/Node/Expression/Binary.php index 537f0d8..8a05969 100644 --- a/lib/Twig/Node/Expression/Binary.php +++ b/lib/Twig/Node/Expression/Binary.php @@ -25,13 +25,13 @@ abstract class Twig_Node_Expression_Binary extends Twig_Node_Expression { $compiler ->raw('(') - ->subcompile($this->left) + ->subcompile($this->getNode('left')) ->raw(') ') ; $this->operator($compiler); $compiler ->raw(' (') - ->subcompile($this->right) + ->subcompile($this->getNode('right')) ->raw(')') ; } diff --git a/lib/Twig/Node/Expression/Compare.php b/lib/Twig/Node/Expression/Compare.php index e1156d2..c87be9a 100644 --- a/lib/Twig/Node/Expression/Compare.php +++ b/lib/Twig/Node/Expression/Compare.php @@ -18,28 +18,28 @@ class Twig_Node_Expression_Compare extends Twig_Node_Expression public function compile($compiler) { - if ('in' === $this->ops->{0}['value']) { + if ('in' === $this->getNode('ops')->getNode('0')->getAttribute('value')) { return $this->compileIn($compiler); } - $this->expr->compile($compiler); + $this->getNode('expr')->compile($compiler); - $nbOps = count($this->ops); + $nbOps = count($this->getNode('ops')); for ($i = 0; $i < $nbOps; $i += 2) { if ($i > 0) { $compiler->raw(' && ($tmp'.($i / 2)); } - $compiler->raw(' '.$this->ops->{$i}['value'].' '); + $compiler->raw(' '.$this->getNode('ops')->getNode($i)->getAttribute('value').' '); if ($i != $nbOps - 2) { $compiler ->raw('($tmp'.(($i / 2) + 1).' = ') - ->subcompile($this->ops->{($i + 1)}) + ->subcompile($this->getNode('ops')->getNode($i + 1)) ->raw(')') ; } else { - $compiler->subcompile($this->ops->{($i + 1)}); + $compiler->subcompile($this->getNode('ops')->getNode($i + 1)); } } @@ -52,9 +52,9 @@ class Twig_Node_Expression_Compare extends Twig_Node_Expression { $compiler ->raw('twig_in_filter(') - ->subcompile($this->expr) + ->subcompile($this->getNode('expr')) ->raw(', ') - ->subcompile($this->ops->{1}) + ->subcompile($this->getNode('ops')->getNode(1)) ->raw(')') ; } diff --git a/lib/Twig/Node/Expression/Conditional.php b/lib/Twig/Node/Expression/Conditional.php index 4440716..c6f3e98 100644 --- a/lib/Twig/Node/Expression/Conditional.php +++ b/lib/Twig/Node/Expression/Conditional.php @@ -20,11 +20,11 @@ class Twig_Node_Expression_Conditional extends Twig_Node_Expression { $compiler ->raw('(') - ->subcompile($this->expr1) + ->subcompile($this->getNode('expr1')) ->raw(') ? (') - ->subcompile($this->expr2) + ->subcompile($this->getNode('expr2')) ->raw(') : (') - ->subcompile($this->expr3) + ->subcompile($this->getNode('expr3')) ->raw(')') ; } diff --git a/lib/Twig/Node/Expression/Constant.php b/lib/Twig/Node/Expression/Constant.php index 5d8d051..9bbaa99 100644 --- a/lib/Twig/Node/Expression/Constant.php +++ b/lib/Twig/Node/Expression/Constant.php @@ -18,6 +18,6 @@ class Twig_Node_Expression_Constant extends Twig_Node_Expression public function compile($compiler) { - $compiler->repr($this['value']); + $compiler->repr($this->getAttribute('value')); } } diff --git a/lib/Twig/Node/Expression/ExtensionReference.php b/lib/Twig/Node/Expression/ExtensionReference.php index 3a65d07..9b0801b 100644 --- a/lib/Twig/Node/Expression/ExtensionReference.php +++ b/lib/Twig/Node/Expression/ExtensionReference.php @@ -30,6 +30,6 @@ class Twig_Node_Expression_ExtensionReference extends Twig_Node_Expression */ public function compile($compiler) { - $compiler->raw(sprintf("\$this->env->getExtension('%s')", $this['name'])); + $compiler->raw(sprintf("\$this->env->getExtension('%s')", $this->getAttribute('name'))); } } diff --git a/lib/Twig/Node/Expression/Filter.php b/lib/Twig/Node/Expression/Filter.php index 9d7c856..204e791 100644 --- a/lib/Twig/Node/Expression/Filter.php +++ b/lib/Twig/Node/Expression/Filter.php @@ -21,9 +21,9 @@ class Twig_Node_Expression_Filter extends Twig_Node_Expression $filterMap = $compiler->getEnvironment()->getFilters(); $postponed = array(); - for ($i = count($this->filters) - 1; $i >= 0; $i -= 2) { - $name = $this->filters->{$i - 1}['value']; - $attrs = $this->filters->{$i}; + for ($i = count($this->getNode('filters')) - 1; $i >= 0; $i -= 2) { + $name = $this->getNode('filters')->getNode($i - 1)->getAttribute('value'); + $attrs = $this->getNode('filters')->getNode($i); if (!isset($filterMap[$name])) { throw new Twig_SyntaxError(sprintf('The filter "%s" does not exist', $name), $this->getLine()); } else { @@ -32,7 +32,7 @@ class Twig_Node_Expression_Filter extends Twig_Node_Expression $postponed[] = $attrs; } - $this->node->compile($compiler); + $this->getNode('node')->compile($compiler); foreach (array_reverse($postponed) as $attributes) { foreach ($attributes as $node) { @@ -48,37 +48,37 @@ class Twig_Node_Expression_Filter extends Twig_Node_Expression public function prependFilter(Twig_Node_Expression_Constant $name, Twig_Node $end) { $filters = array($name, $end); - foreach ($this->filters as $node) { + foreach ($this->getNode('filters') as $node) { $filters[] = $node; } - $this->filters = new Twig_Node($filters, array(), $this->filters->getLine()); + $this->setNode('filters', new Twig_Node($filters, array(), $this->getNode('filters')->getLine())); } public function appendFilter(Twig_Node_Expression_Constant $name, Twig_Node $end) { $filters = array(); - foreach ($this->filters as $node) { + foreach ($this->getNode('filters') as $node) { $filters[] = $node; } $filters[] = $name; $filters[] = $end; - $this->filters = new Twig_Node($filters, array(), $this->filters->getLine()); + $this->setNode('filters', new Twig_Node($filters, array(), $this->getNode('filters')->getLine())); } public function appendFilters(Twig_NodeInterface $filters) { for ($i = 0; $i < count($filters); $i += 2) { - $this->appendFilter($filters->{$i}, $filters->{$i + 1}); + $this->appendFilter($filters->getNode($i), $filters->getNode($i + 1)); } } public function hasFilter($name) { - for ($i = 0; $i < count($this->filters); $i += 2) { - if ($name == $this->filters->{$i}['value']) { + for ($i = 0; $i < count($this->getNode('filters')); $i += 2) { + if ($name == $this->getNode('filters')->getNode($i)->getAttribute('value')) { return true; } } diff --git a/lib/Twig/Node/Expression/GetAttr.php b/lib/Twig/Node/Expression/GetAttr.php index cd905c0..28f7376 100644 --- a/lib/Twig/Node/Expression/GetAttr.php +++ b/lib/Twig/Node/Expression/GetAttr.php @@ -24,13 +24,13 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression { $compiler ->raw('$this->getAttribute(') - ->subcompile($this->node) + ->subcompile($this->getNode('node')) ->raw(', ') - ->subcompile($this->attribute) + ->subcompile($this->getNode('attribute')) ->raw(', array(') ; - foreach ($this->arguments as $node) { + foreach ($this->getNode('arguments') as $node) { $compiler ->subcompile($node) ->raw(', ') @@ -39,7 +39,7 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression $compiler ->raw('), ') - ->repr($this['type']) + ->repr($this->getAttribute('type')) ->raw(')'); } } diff --git a/lib/Twig/Node/Expression/Name.php b/lib/Twig/Node/Expression/Name.php index daf6d80..c4a3acd 100644 --- a/lib/Twig/Node/Expression/Name.php +++ b/lib/Twig/Node/Expression/Name.php @@ -18,14 +18,14 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression public function compile($compiler) { - if ('_self' === $this['name']) { + if ('_self' === $this->getAttribute('name')) { $compiler->raw('$this'); - } elseif ('_context' === $this['name']) { + } elseif ('_context' === $this->getAttribute('name')) { $compiler->raw('$context'); } elseif ($compiler->getEnvironment()->isStrictVariables()) { - $compiler->raw(sprintf('$this->getContext($context, \'%s\')', $this['name'], $this['name'])); + $compiler->raw(sprintf('$this->getContext($context, \'%s\')', $this->getAttribute('name'), $this->getAttribute('name'))); } else { - $compiler->raw(sprintf('(isset($context[\'%s\']) ? $context[\'%s\'] : null)', $this['name'], $this['name'])); + $compiler->raw(sprintf('(isset($context[\'%s\']) ? $context[\'%s\'] : null)', $this->getAttribute('name'), $this->getAttribute('name'))); } } } diff --git a/lib/Twig/Node/Expression/Test.php b/lib/Twig/Node/Expression/Test.php index 95e3689..1b34039 100644 --- a/lib/Twig/Node/Expression/Test.php +++ b/lib/Twig/Node/Expression/Test.php @@ -18,20 +18,20 @@ class Twig_Node_Expression_Test extends Twig_Node_Expression public function compile($compiler) { $testMap = $compiler->getEnvironment()->getTests(); - if (!isset($testMap[$this['name']])) { - throw new Twig_SyntaxError(sprintf('The test "%s" does not exist', $this['name']), $this->getLine()); + if (!isset($testMap[$this->getAttribute('name')])) { + throw new Twig_SyntaxError(sprintf('The test "%s" does not exist', $this->getAttribute('name')), $this->getLine()); } $compiler - ->raw($testMap[$this['name']]->compile().'(') - ->subcompile($this->node) + ->raw($testMap[$this->getAttribute('name')]->compile().'(') + ->subcompile($this->getNode('node')) ; - if (null !== $this->arguments) { + if (null !== $this->getNode('arguments')) { $compiler->raw(', '); - $max = count($this->arguments) - 1; - foreach ($this->arguments as $i => $node) { + $max = count($this->getNode('arguments')) - 1; + foreach ($this->getNode('arguments') as $i => $node) { $compiler->subcompile($node); if ($i != $max) { diff --git a/lib/Twig/Node/Expression/Unary.php b/lib/Twig/Node/Expression/Unary.php index 1042d58..c11c599 100644 --- a/lib/Twig/Node/Expression/Unary.php +++ b/lib/Twig/Node/Expression/Unary.php @@ -21,7 +21,7 @@ abstract class Twig_Node_Expression_Unary extends Twig_Node_Expression $compiler->raw('('); $this->operator($compiler); $compiler - ->subcompile($this->node) + ->subcompile($this->getNode('node')) ->raw(')') ; } diff --git a/lib/Twig/Node/For.php b/lib/Twig/Node/For.php index b1031ee..0e76f4e 100644 --- a/lib/Twig/Node/For.php +++ b/lib/Twig/Node/For.php @@ -37,17 +37,17 @@ class Twig_Node_For extends Twig_Node ->write('$context[\'_parent\'] = (array) $context;'."\n") ; - if (!is_null($this->else)) { + if (!is_null($this->getNode('else'))) { $compiler->write("\$context['_iterated'] = false;\n"); } $compiler ->write("\$context['_seq'] = twig_iterator_to_array(") - ->subcompile($this->seq) + ->subcompile($this->getNode('seq')) ->raw(");\n") ; - if ($this['with_loop']) { + if ($this->getAttribute('with_loop')) { $compiler ->write("\$countable = is_array(\$context['_seq']) || (is_object(\$context['_seq']) && \$context['_seq'] instanceof Countable);\n") ->write("\$length = \$countable ? count(\$context['_seq']) : null;\n") @@ -71,20 +71,20 @@ class Twig_Node_For extends Twig_Node $compiler ->write("foreach (\$context['_seq'] as ") - ->subcompile($this->key_target) + ->subcompile($this->getNode('key_target')) ->raw(" => ") - ->subcompile($this->value_target) + ->subcompile($this->getNode('value_target')) ->raw(") {\n") ->indent() ; - if (!is_null($this->else)) { + if (!is_null($this->getNode('else'))) { $compiler->write("\$context['_iterated'] = true;\n"); } - $compiler->subcompile($this->body); + $compiler->subcompile($this->getNode('body')); - if ($this['with_loop']) { + if ($this->getAttribute('with_loop')) { $compiler ->write("++\$context['loop']['index0'];\n") ->write("++\$context['loop']['index'];\n") @@ -104,11 +104,11 @@ class Twig_Node_For extends Twig_Node ->write("}\n") ; - if (!is_null($this->else)) { + if (!is_null($this->getNode('else'))) { $compiler ->write("if (!\$context['_iterated']) {\n") ->indent() - ->subcompile($this->else) + ->subcompile($this->getNode('else')) ->outdent() ->write("}\n") ; @@ -117,7 +117,7 @@ class Twig_Node_For extends Twig_Node $compiler->write('$_parent = $context[\'_parent\'];'."\n"); // remove some "private" loop variables (needed for nested loops) - $compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\''.$this->key_target['name'].'\'], $context[\''.$this->value_target['name'].'\'], $context[\'_parent\'], $context[\'loop\']);'."\n"); + $compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\''.$this->getNode('key_target')->getAttribute('name').'\'], $context[\''.$this->getNode('value_target')->getAttribute('name').'\'], $context[\'_parent\'], $context[\'loop\']);'."\n"); /// keep the values set in the inner context for variables defined in the outer context $compiler->write('$context = array_merge($_parent, array_intersect_key($context, $_parent));'."\n"); diff --git a/lib/Twig/Node/If.php b/lib/Twig/Node/If.php index 985745f..1530893 100644 --- a/lib/Twig/Node/If.php +++ b/lib/Twig/Node/If.php @@ -32,7 +32,7 @@ class Twig_Node_If extends Twig_Node public function compile($compiler) { $compiler->addDebugInfo($this); - for ($i = 0; $i < count($this->tests); $i += 2) { + for ($i = 0; $i < count($this->getNode('tests')); $i += 2) { if ($i > 0) { $compiler ->outdent() @@ -45,19 +45,19 @@ class Twig_Node_If extends Twig_Node } $compiler - ->subcompile($this->tests->{$i}) + ->subcompile($this->getNode('tests')->getNode($i)) ->raw(") {\n") ->indent() - ->subcompile($this->tests->{($i + 1)}) + ->subcompile($this->getNode('tests')->getNode($i + 1)) ; } - if (isset($this->else) && null !== $this->else) { + if ($this->hasNode('else') && null !== $this->getNode('else')) { $compiler ->outdent() ->write("} else {\n") ->indent() - ->subcompile($this->else) + ->subcompile($this->getNode('else')) ; } diff --git a/lib/Twig/Node/Import.php b/lib/Twig/Node/Import.php index 0e94f3c..90f90cf 100644 --- a/lib/Twig/Node/Import.php +++ b/lib/Twig/Node/Import.php @@ -33,16 +33,16 @@ class Twig_Node_Import extends Twig_Node $compiler ->addDebugInfo($this) ->write('') - ->subcompile($this->var) + ->subcompile($this->getNode('var')) ->raw(' = ') ; - if ($this->expr instanceof Twig_Node_Expression_Name && '_self' === $this->expr['name']) { + if ($this->getNode('expr') instanceof Twig_Node_Expression_Name && '_self' === $this->getNode('expr')->getAttribute('name')) { $compiler->raw("\$this"); } else { $compiler ->raw('$this->env->loadTemplate(') - ->subcompile($this->expr) + ->subcompile($this->getNode('expr')) ->raw(", true)") ; } diff --git a/lib/Twig/Node/Include.php b/lib/Twig/Node/Include.php index d7c9fd4..15c1f1d 100644 --- a/lib/Twig/Node/Include.php +++ b/lib/Twig/Node/Include.php @@ -33,16 +33,16 @@ class Twig_Node_Include extends Twig_Node { $compiler->addDebugInfo($this); - if ($this->expr instanceof Twig_Node_Expression_Constant) { + if ($this->getNode('expr') instanceof Twig_Node_Expression_Constant) { $compiler ->write("\$this->env->loadTemplate(") - ->subcompile($this->expr) + ->subcompile($this->getNode('expr')) ->raw(")->display(") ; } else { $compiler ->write("\$template = ") - ->subcompile($this->expr) + ->subcompile($this->getNode('expr')) ->raw(";\n") ->write("if (!\$template") ->raw(" instanceof Twig_Template) {\n") @@ -54,10 +54,10 @@ class Twig_Node_Include extends Twig_Node ; } - if (null === $this->variables) { + if (null === $this->getNode('variables')) { $compiler->raw('$context'); } else { - $compiler->subcompile($this->variables); + $compiler->subcompile($this->getNode('variables')); } $compiler->raw(");\n"); diff --git a/lib/Twig/Node/Macro.php b/lib/Twig/Node/Macro.php index 7db4a98..7f75c17 100644 --- a/lib/Twig/Node/Macro.php +++ b/lib/Twig/Node/Macro.php @@ -31,23 +31,23 @@ class Twig_Node_Macro extends Twig_Node public function compile($compiler) { $arguments = array(); - foreach ($this->arguments as $argument) { - $arguments[] = '$'.$argument['name'].' = null'; + foreach ($this->getNode('arguments') as $argument) { + $arguments[] = '$'.$argument->getAttribute('name').' = null'; } $compiler ->addDebugInfo($this) - ->write(sprintf("public function get%s(%s)\n", $this['name'], implode(', ', $arguments)), "{\n") + ->write(sprintf("public function get%s(%s)\n", $this->getAttribute('name'), implode(', ', $arguments)), "{\n") ->indent() ->write("\$context = array(\n") ->indent() ; - foreach ($this->arguments as $argument) { + foreach ($this->getNode('arguments') as $argument) { $compiler ->write('') - ->string($argument['name']) - ->raw(' => $'.$argument['name']) + ->string($argument->getAttribute('name')) + ->raw(' => $'.$argument->getAttribute('name')) ->raw(",\n") ; } @@ -55,7 +55,7 @@ class Twig_Node_Macro extends Twig_Node $compiler ->outdent() ->write(");\n\n") - ->subcompile($this->body) + ->subcompile($this->getNode('body')) ->outdent() ->write("}\n\n") ; diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index 630c25d..9c37a3b 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -38,7 +38,7 @@ class Twig_Node_Module extends Twig_Node { $this->compileClassHeader($compiler); - if (count($this->blocks)) { + if (count($this->getNode('blocks'))) { $this->compileConstructor($compiler); } @@ -50,7 +50,7 @@ class Twig_Node_Module extends Twig_Node $this->compileDisplayFooter($compiler); - $compiler->subcompile($this->blocks); + $compiler->subcompile($this->getNode('blocks')); $this->compileMacros($compiler); @@ -59,7 +59,7 @@ class Twig_Node_Module extends Twig_Node protected function compileGetParent($compiler) { - if (null === $this->parent) { + if (null === $this->getNode('parent')) { return; } @@ -70,16 +70,16 @@ class Twig_Node_Module extends Twig_Node ->indent(); ; - if ($this->parent instanceof Twig_Node_Expression_Constant) { + if ($this->getNode('parent') instanceof Twig_Node_Expression_Constant) { $compiler ->write("\$this->parent = \$this->env->loadTemplate(") - ->subcompile($this->parent) + ->subcompile($this->getNode('parent')) ->raw(");\n") ; } else { $compiler ->write("\$this->parent = ") - ->subcompile($this->parent) + ->subcompile($this->getNode('parent')) ->raw(";\n") ->write("if (!\$this->parent") ->raw(" instanceof Twig_Template) {\n") @@ -101,9 +101,9 @@ class Twig_Node_Module extends Twig_Node protected function compileDisplayBody($compiler) { - if (null !== $this->parent) { + if (null !== $this->getNode('parent')) { // remove all but import nodes - foreach ($this->body as $node) { + foreach ($this->getNode('body') as $node) { if ($node instanceof Twig_Node_Import) { $compiler->subcompile($node); } @@ -113,7 +113,7 @@ class Twig_Node_Module extends Twig_Node ->write("\$this->getParent(\$context)->display(\$context, array_merge(\$this->blocks, \$blocks));\n") ; } else { - $compiler->subcompile($this->body); + $compiler->subcompile($this->getNode('body')); } } @@ -122,14 +122,14 @@ class Twig_Node_Module extends Twig_Node $compiler ->write("write("/* ".str_replace('*/', '* /', $this['filename'])." */\n") - ->write('class '.$compiler->getEnvironment()->getTemplateClass($this['filename'])) + ->write("/* ".str_replace('*/', '* /', $this->getAttribute('filename'))." */\n") + ->write('class '.$compiler->getEnvironment()->getTemplateClass($this->getAttribute('filename'))) ->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass())) ->write("{\n") ->indent() ; - if (null !== $this->parent) { + if (null !== $this->getNode('parent')) { $compiler->write("protected \$parent;\n\n"); } } @@ -144,7 +144,7 @@ class Twig_Node_Module extends Twig_Node ->indent() ; - foreach ($this->blocks as $name => $node) { + foreach ($this->getNode('blocks') as $name => $node) { $compiler ->write(sprintf("'%s' => array(\$this, 'block_%s'),\n", $name, $name)) ; @@ -184,6 +184,6 @@ class Twig_Node_Module extends Twig_Node protected function compileMacros($compiler) { - $compiler->subcompile($this->macros); + $compiler->subcompile($this->getNode('macros')); } } diff --git a/lib/Twig/Node/Parent.php b/lib/Twig/Node/Parent.php index dc779cf..b40903d 100644 --- a/lib/Twig/Node/Parent.php +++ b/lib/Twig/Node/Parent.php @@ -34,7 +34,7 @@ class Twig_Node_Parent extends Twig_Node $compiler ->addDebugInfo($this) ->write("\$this->getParentBlock(") - ->string($this['name']) + ->string($this->getAttribute('name')) ->raw(", \$context, \$blocks);\n") ; } diff --git a/lib/Twig/Node/Print.php b/lib/Twig/Node/Print.php index b5bd0a7..e64f588 100644 --- a/lib/Twig/Node/Print.php +++ b/lib/Twig/Node/Print.php @@ -34,7 +34,7 @@ class Twig_Node_Print extends Twig_Node $compiler ->addDebugInfo($this) ->write('echo ') - ->subcompile($this->expr) + ->subcompile($this->getNode('expr')) ->raw(";\n") ; } diff --git a/lib/Twig/Node/Sandbox.php b/lib/Twig/Node/Sandbox.php index 98ed92a..bd2e2d0 100644 --- a/lib/Twig/Node/Sandbox.php +++ b/lib/Twig/Node/Sandbox.php @@ -38,7 +38,7 @@ class Twig_Node_Sandbox extends Twig_Node ->write("\$sandbox->enableSandbox();\n") ->outdent() ->write("}\n") - ->subcompile($this->body) + ->subcompile($this->getNode('body')) ->write("if (!\$alreadySandboxed) {\n") ->indent() ->write("\$sandbox->disableSandbox();\n") diff --git a/lib/Twig/Node/SandboxedModule.php b/lib/Twig/Node/SandboxedModule.php index c2f3cb7..0b3baa6 100644 --- a/lib/Twig/Node/SandboxedModule.php +++ b/lib/Twig/Node/SandboxedModule.php @@ -24,7 +24,7 @@ class Twig_Node_SandboxedModule extends Twig_Node_Module public function __construct(Twig_Node_Module $node, array $usedFilters, array $usedTags) { - parent::__construct($node->body, $node->parent, $node->blocks, $node->macros, $node['filename'], $node->getLine(), $node->getNodeTag()); + parent::__construct($node->getNode('body'), $node->getNode('parent'), $node->getNode('blocks'), $node->getNode('macros'), $node->getAttribute('filename'), $node->getLine(), $node->getNodeTag()); $this->usedFilters = $usedFilters; $this->usedTags = $usedTags; @@ -32,7 +32,7 @@ class Twig_Node_SandboxedModule extends Twig_Node_Module protected function compileDisplayBody($compiler) { - if (null === $this->parent) { + if (null === $this->getNode('parent')) { $compiler->write("\$this->checkSecurity();\n"); } @@ -54,7 +54,7 @@ class Twig_Node_SandboxedModule extends Twig_Node_Module ->write(");\n") ; - if (null !== $this->parent) { + if (null !== $this->getNode('parent')) { $compiler ->raw("\n") ->write("\$this->parent->checkSecurity();\n") diff --git a/lib/Twig/Node/SandboxedPrint.php b/lib/Twig/Node/SandboxedPrint.php index d5d032f..d8838df 100644 --- a/lib/Twig/Node/SandboxedPrint.php +++ b/lib/Twig/Node/SandboxedPrint.php @@ -25,7 +25,7 @@ class Twig_Node_SandboxedPrint extends Twig_Node_Print { public function __construct(Twig_Node_Print $node) { - parent::__construct($node->expr, $node->getLine(), $node->getNodeTag()); + parent::__construct($node->getNode('expr'), $node->getLine(), $node->getNodeTag()); } /** @@ -38,11 +38,11 @@ class Twig_Node_SandboxedPrint extends Twig_Node_Print $compiler ->addDebugInfo($this) ->write('if ($this->env->hasExtension(\'sandbox\') && is_object(') - ->subcompile($this->expr) + ->subcompile($this->getNode('expr')) ->raw(')) {'."\n") ->indent() ->write('$this->env->getExtension(\'sandbox\')->checkMethodAllowed(') - ->subcompile($this->expr) + ->subcompile($this->getNode('expr')) ->raw(', \'__toString\');'."\n") ->outdent() ->write('}'."\n") diff --git a/lib/Twig/Node/Set.php b/lib/Twig/Node/Set.php index 66fb7ce..78942bc 100644 --- a/lib/Twig/Node/Set.php +++ b/lib/Twig/Node/Set.php @@ -32,9 +32,9 @@ class Twig_Node_Set extends Twig_Node { $compiler->addDebugInfo($this); - if (count($this->names) > 1) { + if (count($this->getNode('names')) > 1) { $compiler->write('list('); - foreach ($this->names as $idx => $node) { + foreach ($this->getNode('names') as $idx => $node) { if ($idx) { $compiler->raw(', '); } @@ -43,26 +43,26 @@ class Twig_Node_Set extends Twig_Node } $compiler->raw(')'); } else { - if ($this['capture']) { + if ($this->getAttribute('capture')) { $compiler ->write("ob_start();\n") - ->subcompile($this->values) + ->subcompile($this->getNode('values')) ; } - $compiler->subcompile($this->names, false); + $compiler->subcompile($this->getNode('names'), false); - if ($this['capture']) { + if ($this->getAttribute('capture')) { $compiler->raw(" = ob_get_clean()"); } } - if (!$this['capture']) { + if (!$this->getAttribute('capture')) { $compiler->raw(' = '); - if (count($this->names) > 1) { + if (count($this->getNode('names')) > 1) { $compiler->write('array('); - foreach ($this->values as $idx => $value) { + foreach ($this->getNode('values') as $idx => $value) { if ($idx) { $compiler->raw(', '); } @@ -71,7 +71,7 @@ class Twig_Node_Set extends Twig_Node } $compiler->raw(')'); } else { - $compiler->subcompile($this->values); + $compiler->subcompile($this->getNode('values')); } } diff --git a/lib/Twig/Node/Text.php b/lib/Twig/Node/Text.php index f6938c7..8a3ac9c 100644 --- a/lib/Twig/Node/Text.php +++ b/lib/Twig/Node/Text.php @@ -34,7 +34,7 @@ class Twig_Node_Text extends Twig_Node $compiler ->addDebugInfo($this) ->write('echo ') - ->string($this['data']) + ->string($this->getAttribute('data')) ->raw(";\n") ; } diff --git a/lib/Twig/Node/Trans.php b/lib/Twig/Node/Trans.php index 6a45f93..3112be4 100644 --- a/lib/Twig/Node/Trans.php +++ b/lib/Twig/Node/Trans.php @@ -32,15 +32,15 @@ class Twig_Node_Trans extends Twig_Node { $compiler->addDebugInfo($this); - list($msg, $vars) = $this->compileString($this->body); + list($msg, $vars) = $this->compileString($this->getNode('body')); - if (null !== $this->plural) { - list($msg1, $vars1) = $this->compileString($this->plural); + if (null !== $this->getNode('plural')) { + list($msg1, $vars1) = $this->compileString($this->getNode('plural')); $vars = array_merge($vars, $vars1); } - $function = null === $this->plural ? 'gettext' : 'ngettext'; + $function = null === $this->getNode('plural') ? 'gettext' : 'ngettext'; if ($vars) { $compiler @@ -48,12 +48,12 @@ class Twig_Node_Trans extends Twig_Node ->subcompile($msg) ; - if (null !== $this->plural) { + if (null !== $this->getNode('plural')) { $compiler ->raw(', ') ->subcompile($msg1) ->raw(', abs(') - ->subcompile($this->count) + ->subcompile($this->getNode('count')) ->raw(')') ; } @@ -61,16 +61,16 @@ class Twig_Node_Trans extends Twig_Node $compiler->raw('), array('); foreach ($vars as $var) { - if ('count' === $var['name']) { + if ('count' === $var->getAttribute('name')) { $compiler ->string('%count%') ->raw(' => abs(') - ->subcompile($this->count) + ->subcompile($this->getNode('count')) ->raw('), ') ; } else { $compiler - ->string('%'.$var['name'].'%') + ->string('%'.$var->getAttribute('name').'%') ->raw(' => ') ->subcompile($var) ->raw(', ') @@ -85,12 +85,12 @@ class Twig_Node_Trans extends Twig_Node ->subcompile($msg) ; - if (null !== $this->plural) { + if (null !== $this->getNode('plural')) { $compiler ->raw(', ') ->subcompile($msg1) ->raw(', abs(') - ->subcompile($this->count) + ->subcompile($this->getNode('count')) ->raw(')') ; } @@ -109,14 +109,14 @@ class Twig_Node_Trans extends Twig_Node $vars = array(); foreach ($body as $node) { if ($node instanceof Twig_Node_Print) { - $n = $node->expr; + $n = $node->getNode('expr'); while ($n instanceof Twig_Node_Expression_Filter) { - $n = $n->node; + $n = $n->getNode('node'); } - $msg .= sprintf('%%%s%%', $n['name']); - $vars[] = new Twig_Node_Expression_Name($n['name'], $n->getLine()); + $msg .= sprintf('%%%s%%', $n->getAttribute('name')); + $vars[] = new Twig_Node_Expression_Name($n->getAttribute('name'), $n->getLine()); } else { - $msg .= $node['data']; + $msg .= $node->getAttribute('data'); } } diff --git a/lib/Twig/NodeTraverser.php b/lib/Twig/NodeTraverser.php index 6450954..ac9769a 100644 --- a/lib/Twig/NodeTraverser.php +++ b/lib/Twig/NodeTraverser.php @@ -65,9 +65,9 @@ class Twig_NodeTraverser foreach ($node as $k => $n) { if (false !== $n = $this->traverse($n)) { - $node->$k = $n; + $node->setNode($k, $n); } else { - unset($node->$k); + $node->removeNode($k); } } diff --git a/lib/Twig/NodeVisitor/Escaper.php b/lib/Twig/NodeVisitor/Escaper.php index 269dc47..8cfc08d 100644 --- a/lib/Twig/NodeVisitor/Escaper.php +++ b/lib/Twig/NodeVisitor/Escaper.php @@ -32,11 +32,11 @@ class Twig_NodeVisitor_Escaper implements Twig_NodeVisitorInterface public function enterNode(Twig_NodeInterface $node, Twig_Environment $env) { if ($node instanceof Twig_Node_AutoEscape) { - $this->statusStack[] = $node['value']; + $this->statusStack[] = $node->getAttribute('value'); } elseif ($node instanceof Twig_Node_Print) { return $this->escapeNode($node, $env, $this->needEscaping($env)); } elseif ($node instanceof Twig_Node_Block) { - $this->statusStack[] = isset($this->blocks[$node['name']]) ? $this->blocks[$node['name']] : $this->needEscaping($env); + $this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env); } return $node; @@ -55,7 +55,7 @@ class Twig_NodeVisitor_Escaper implements Twig_NodeVisitorInterface if ($node instanceof Twig_Node_AutoEscape || $node instanceof Twig_Node_Block) { array_pop($this->statusStack); } elseif ($node instanceof Twig_Node_BlockReference) { - $this->blocks[$node['name']] = $this->needEscaping($env); + $this->blocks[$node->getAttribute('name')] = $this->needEscaping($env); } return $node; @@ -67,18 +67,18 @@ class Twig_NodeVisitor_Escaper implements Twig_NodeVisitorInterface return $node; } - $expression = $node instanceof Twig_Node_Print ? $node->expr : $node; + $expression = $node instanceof Twig_Node_Print ? $node->getNode('expr') : $node; if ($expression instanceof Twig_Node_Expression_Filter) { // don't escape if the primary node of the filter is not a variable - if (!$expression->node instanceof Twig_Node_Expression_GetAttr && !$expression->node instanceof Twig_Node_Expression_Name) { + if (!$expression->getNode('node') instanceof Twig_Node_Expression_GetAttr && !$expression->getNode('node') instanceof Twig_Node_Expression_Name) { return $node; } // don't escape if there is already an "escaper" in the filter chain $filterMap = $env->getFilters(); - for ($i = 0; $i < count($expression->filters); $i += 2) { - $name = $expression->filters->{$i}['value']; + for ($i = 0; $i < count($expression->getNode('filters')); $i += 2) { + $name = $expression->getNode('filters')->getNode($i)->getAttribute('value'); if (isset($filterMap[$name]) && $filterMap[$name]->isEscaper()) { return $node; } @@ -91,9 +91,9 @@ class Twig_NodeVisitor_Escaper implements Twig_NodeVisitorInterface // escape if ($expression instanceof Twig_Node_Expression_Filter) { // escape all variables in filters arguments - for ($i = 0; $i < count($expression->filters); $i += 2) { - foreach ($expression->filters->{$i + 1} as $j => $n) { - $expression->filters->{$i + 1}->{$j} = $this->escapeNode($n, $env, $type); + for ($i = 0; $i < count($expression->getNode('filters')); $i += 2) { + foreach ($expression->getNode('filters')->getNode($i + 1) as $j => $n) { + $expression->getNode('filters')->getNode($i + 1)->setNode($j, $this->escapeNode($n, $env, $type)); } } diff --git a/lib/Twig/NodeVisitor/Sandbox.php b/lib/Twig/NodeVisitor/Sandbox.php index 921760f..8dd1230 100644 --- a/lib/Twig/NodeVisitor/Sandbox.php +++ b/lib/Twig/NodeVisitor/Sandbox.php @@ -46,13 +46,13 @@ class Twig_NodeVisitor_Sandbox implements Twig_NodeVisitorInterface // look for filters if ($node instanceof Twig_Node_Expression_Filter) { - for ($i = 0; $i < count($node->filters); $i += 2) { - $this->filters[] = $node->filters->{$i}['value']; + for ($i = 0; $i < count($node->getNode('filters')); $i += 2) { + $this->filters[] = $node->getNode('filters')->getNode($i)->getAttribute('value'); } } // look for simple print statements ({{ article }}) - if ($node instanceof Twig_Node_Print && $node->expr instanceof Twig_Node_Expression_Name) { + if ($node instanceof Twig_Node_Print && $node->getNode('expr') instanceof Twig_Node_Expression_Name) { return new Twig_Node_SandboxedPrint($node); } } diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 2eb8883..ab75288 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -216,7 +216,7 @@ class Twig_Parser implements Twig_ParserInterface foreach ($body as $node) { if ( - ($node instanceof Twig_Node_Text && !preg_match('/^\s*$/s', $node['data'])) + ($node instanceof Twig_Node_Text && !preg_match('/^\s*$/s', $node->getAttribute('data'))) || (!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference) ) { diff --git a/lib/Twig/TokenParser/For.php b/lib/Twig/TokenParser/For.php index 24afd6b..758fb4a 100644 --- a/lib/Twig/TokenParser/For.php +++ b/lib/Twig/TokenParser/For.php @@ -43,11 +43,11 @@ class Twig_TokenParser_For extends Twig_TokenParser $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); if (count($targets) > 1) { - $keyTarget = $targets->{0}; - $valueTarget = $targets->{1}; + $keyTarget = $targets->getNode(0); + $valueTarget = $targets->getNode(1); } else { $keyTarget = new Twig_Node_Expression_AssignName('_key', $lineno); - $valueTarget = $targets->{0}; + $valueTarget = $targets->getNode(0); } return new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, $withLoop, $lineno, $this->getTag()); diff --git a/test/Twig/Tests/Node/AutoEscapeTest.php b/test/Twig/Tests/Node/AutoEscapeTest.php index 5438390..ebfcb48 100644 --- a/test/Twig/Tests/Node/AutoEscapeTest.php +++ b/test/Twig/Tests/Node/AutoEscapeTest.php @@ -21,8 +21,8 @@ class Twig_Tests_Node_AutoEscapeTest extends Twig_Tests_Node_TestCase $body = new Twig_Node(array(new Twig_Node_Text('foo', 0))); $node = new Twig_Node_AutoEscape(true, $body, 0); - $this->assertEquals($body, $node->body); - $this->assertEquals(true, $node['value']); + $this->assertEquals($body, $node->getNode('body')); + $this->assertEquals(true, $node->getAttribute('value')); } /** diff --git a/test/Twig/Tests/Node/BlockReferenceTest.php b/test/Twig/Tests/Node/BlockReferenceTest.php index b5e7fcf..f77f7f0 100644 --- a/test/Twig/Tests/Node/BlockReferenceTest.php +++ b/test/Twig/Tests/Node/BlockReferenceTest.php @@ -20,7 +20,7 @@ class Twig_Tests_Node_BlockReferenceTest extends Twig_Tests_Node_TestCase { $node = new Twig_Node_BlockReference('foo', 0); - $this->assertEquals('foo', $node['name']); + $this->assertEquals('foo', $node->getAttribute('name')); } /** diff --git a/test/Twig/Tests/Node/BlockTest.php b/test/Twig/Tests/Node/BlockTest.php index eb4c4ff..6bc5e79 100644 --- a/test/Twig/Tests/Node/BlockTest.php +++ b/test/Twig/Tests/Node/BlockTest.php @@ -21,8 +21,8 @@ class Twig_Tests_Node_BlockTest extends Twig_Tests_Node_TestCase $body = new Twig_Node_Text('foo', 0); $node = new Twig_Node_Block('foo', $body, 0); - $this->assertEquals($body, $node->body); - $this->assertEquals('foo', $node['name']); + $this->assertEquals($body, $node->getNode('body')); + $this->assertEquals('foo', $node->getAttribute('name')); } /** diff --git a/test/Twig/Tests/Node/Expression/ArrayTest.php b/test/Twig/Tests/Node/Expression/ArrayTest.php index 6729225..1048cf4 100644 --- a/test/Twig/Tests/Node/Expression/ArrayTest.php +++ b/test/Twig/Tests/Node/Expression/ArrayTest.php @@ -21,7 +21,7 @@ class Twig_Tests_Node_Expression_ArrayTest extends Twig_Tests_Node_TestCase $elements = array('foo' => $foo = new Twig_Node_Expression_Constant('bar', 0)); $node = new Twig_Node_Expression_Array($elements, 0); - $this->assertEquals($foo, $node->foo); + $this->assertEquals($foo, $node->getNode('foo')); } /** diff --git a/test/Twig/Tests/Node/Expression/AssignNameTest.php b/test/Twig/Tests/Node/Expression/AssignNameTest.php index 5cc9988..28bc667 100644 --- a/test/Twig/Tests/Node/Expression/AssignNameTest.php +++ b/test/Twig/Tests/Node/Expression/AssignNameTest.php @@ -20,7 +20,7 @@ class Twig_Tests_Node_Expression_AssignNameTest extends Twig_Tests_Node_TestCase { $node = new Twig_Node_Expression_AssignName('foo', 0); - $this->assertEquals('foo', $node['name']); + $this->assertEquals('foo', $node->getAttribute('name')); } /** diff --git a/test/Twig/Tests/Node/Expression/Binary/AddTest.php b/test/Twig/Tests/Node/Expression/Binary/AddTest.php index ed49187..f2bec4c 100644 --- a/test/Twig/Tests/Node/Expression/Binary/AddTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/AddTest.php @@ -22,8 +22,8 @@ class Twig_Tests_Node_Expression_Binary_AddTest extends Twig_Tests_Node_TestCase $right = new Twig_Node_Expression_Constant(2, 0); $node = new Twig_Node_Expression_Binary_Add($left, $right, 0); - $this->assertEquals($left, $node->left); - $this->assertEquals($right, $node->right); + $this->assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); } /** diff --git a/test/Twig/Tests/Node/Expression/Binary/AndTest.php b/test/Twig/Tests/Node/Expression/Binary/AndTest.php index 0db4cb2..fc67850 100644 --- a/test/Twig/Tests/Node/Expression/Binary/AndTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/AndTest.php @@ -22,8 +22,8 @@ class Twig_Tests_Node_Expression_Binary_AndTest extends Twig_Tests_Node_TestCase $right = new Twig_Node_Expression_Constant(2, 0); $node = new Twig_Node_Expression_Binary_And($left, $right, 0); - $this->assertEquals($left, $node->left); - $this->assertEquals($right, $node->right); + $this->assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); } /** diff --git a/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php b/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php index a24a86a..4c16171 100644 --- a/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php @@ -22,8 +22,8 @@ class Twig_Tests_Node_Expression_Binary_ConcatTest extends Twig_Tests_Node_TestC $right = new Twig_Node_Expression_Constant(2, 0); $node = new Twig_Node_Expression_Binary_Concat($left, $right, 0); - $this->assertEquals($left, $node->left); - $this->assertEquals($right, $node->right); + $this->assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); } /** diff --git a/test/Twig/Tests/Node/Expression/Binary/DivTest.php b/test/Twig/Tests/Node/Expression/Binary/DivTest.php index 3bea350..9a63994 100644 --- a/test/Twig/Tests/Node/Expression/Binary/DivTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/DivTest.php @@ -22,8 +22,8 @@ class Twig_Tests_Node_Expression_Binary_DivTest extends Twig_Tests_Node_TestCase $right = new Twig_Node_Expression_Constant(2, 0); $node = new Twig_Node_Expression_Binary_Div($left, $right, 0); - $this->assertEquals($left, $node->left); - $this->assertEquals($right, $node->right); + $this->assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); } /** diff --git a/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php b/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php index 046e9be..f900b15 100644 --- a/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php @@ -22,8 +22,8 @@ class Twig_Tests_Node_Expression_Binary_FloorDivTest extends Twig_Tests_Node_Tes $right = new Twig_Node_Expression_Constant(2, 0); $node = new Twig_Node_Expression_Binary_FloorDiv($left, $right, 0); - $this->assertEquals($left, $node->left); - $this->assertEquals($right, $node->right); + $this->assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); } /** diff --git a/test/Twig/Tests/Node/Expression/Binary/ModTest.php b/test/Twig/Tests/Node/Expression/Binary/ModTest.php index c56d39c..88d82a0 100644 --- a/test/Twig/Tests/Node/Expression/Binary/ModTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/ModTest.php @@ -22,8 +22,8 @@ class Twig_Tests_Node_Expression_Binary_ModTest extends Twig_Tests_Node_TestCase $right = new Twig_Node_Expression_Constant(2, 0); $node = new Twig_Node_Expression_Binary_Mod($left, $right, 0); - $this->assertEquals($left, $node->left); - $this->assertEquals($right, $node->right); + $this->assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); } /** diff --git a/test/Twig/Tests/Node/Expression/Binary/MulTest.php b/test/Twig/Tests/Node/Expression/Binary/MulTest.php index 27be8ac..c1cccb0 100644 --- a/test/Twig/Tests/Node/Expression/Binary/MulTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/MulTest.php @@ -22,8 +22,8 @@ class Twig_Tests_Node_Expression_Binary_MulTest extends Twig_Tests_Node_TestCase $right = new Twig_Node_Expression_Constant(2, 0); $node = new Twig_Node_Expression_Binary_Mul($left, $right, 0); - $this->assertEquals($left, $node->left); - $this->assertEquals($right, $node->right); + $this->assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); } /** diff --git a/test/Twig/Tests/Node/Expression/Binary/OrTest.php b/test/Twig/Tests/Node/Expression/Binary/OrTest.php index ca05101..afea4ff 100644 --- a/test/Twig/Tests/Node/Expression/Binary/OrTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/OrTest.php @@ -22,8 +22,8 @@ class Twig_Tests_Node_Expression_Binary_OrTest extends Twig_Tests_Node_TestCase $right = new Twig_Node_Expression_Constant(2, 0); $node = new Twig_Node_Expression_Binary_Or($left, $right, 0); - $this->assertEquals($left, $node->left); - $this->assertEquals($right, $node->right); + $this->assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); } /** diff --git a/test/Twig/Tests/Node/Expression/Binary/SubTest.php b/test/Twig/Tests/Node/Expression/Binary/SubTest.php index ac13130..3b00e77 100644 --- a/test/Twig/Tests/Node/Expression/Binary/SubTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/SubTest.php @@ -22,8 +22,8 @@ class Twig_Tests_Node_Expression_Binary_SubTest extends Twig_Tests_Node_TestCase $right = new Twig_Node_Expression_Constant(2, 0); $node = new Twig_Node_Expression_Binary_Sub($left, $right, 0); - $this->assertEquals($left, $node->left); - $this->assertEquals($right, $node->right); + $this->assertEquals($left, $node->getNode('left')); + $this->assertEquals($right, $node->getNode('right')); } /** diff --git a/test/Twig/Tests/Node/Expression/CompareTest.php b/test/Twig/Tests/Node/Expression/CompareTest.php index 0c08bf9..fb98ff8 100644 --- a/test/Twig/Tests/Node/Expression/CompareTest.php +++ b/test/Twig/Tests/Node/Expression/CompareTest.php @@ -25,8 +25,8 @@ class Twig_Tests_Node_Expression_CompareTest extends Twig_Tests_Node_TestCase ), array(), 0); $node = new Twig_Node_Expression_Compare($expr, $ops, 0); - $this->assertEquals($expr, $node->expr); - $this->assertEquals($ops, $node->ops); + $this->assertEquals($expr, $node->getNode('expr')); + $this->assertEquals($ops, $node->getNode('ops')); } /** diff --git a/test/Twig/Tests/Node/Expression/ConditionalTest.php b/test/Twig/Tests/Node/Expression/ConditionalTest.php index 3b22fb0..f7cce28 100644 --- a/test/Twig/Tests/Node/Expression/ConditionalTest.php +++ b/test/Twig/Tests/Node/Expression/ConditionalTest.php @@ -23,9 +23,9 @@ class Twig_Tests_Node_Expression_ConditionalTest extends Twig_Tests_Node_TestCas $expr3 = new Twig_Node_Expression_Constant(3, 0); $node = new Twig_Node_Expression_Conditional($expr1, $expr2, $expr3, 0); - $this->assertEquals($expr1, $node->expr1); - $this->assertEquals($expr2, $node->expr2); - $this->assertEquals($expr3, $node->expr3); + $this->assertEquals($expr1, $node->getNode('expr1')); + $this->assertEquals($expr2, $node->getNode('expr2')); + $this->assertEquals($expr3, $node->getNode('expr3')); } /** diff --git a/test/Twig/Tests/Node/Expression/ConstantTest.php b/test/Twig/Tests/Node/Expression/ConstantTest.php index 2824518..0cf3867 100644 --- a/test/Twig/Tests/Node/Expression/ConstantTest.php +++ b/test/Twig/Tests/Node/Expression/ConstantTest.php @@ -20,7 +20,7 @@ class Twig_Tests_Node_Expression_ConstantTest extends Twig_Tests_Node_TestCase { $node = new Twig_Node_Expression_Constant('foo', 0); - $this->assertEquals('foo', $node['value']); + $this->assertEquals('foo', $node->getAttribute('value')); } /** diff --git a/test/Twig/Tests/Node/Expression/FilterTest.php b/test/Twig/Tests/Node/Expression/FilterTest.php index 0cdd199..1134d90 100644 --- a/test/Twig/Tests/Node/Expression/FilterTest.php +++ b/test/Twig/Tests/Node/Expression/FilterTest.php @@ -25,8 +25,8 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Tests_Node_TestCase ), array(), 0); $node = new Twig_Node_Expression_Filter($expr, $filters, 0); - $this->assertEquals($expr, $node->node); - $this->assertEquals($filters, $node->filters); + $this->assertEquals($expr, $node->getNode('node')); + $this->assertEquals($filters, $node->getNode('filters')); } /** @@ -68,7 +68,7 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Tests_Node_TestCase new Twig_Node(), ), array(), 0); - $this->assertEquals($filters, $node->filters); + $this->assertEquals($filters, $node->getNode('filters')); } /** @@ -94,7 +94,7 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Tests_Node_TestCase $b, ), array(), 0); - $this->assertEquals($filters, $node->filters); + $this->assertEquals($filters, $node->getNode('filters')); } /** @@ -122,7 +122,7 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Tests_Node_TestCase $b, ), array(), 0); - $this->assertEquals($filters, $node->filters); + $this->assertEquals($filters, $node->getNode('filters')); } /** diff --git a/test/Twig/Tests/Node/Expression/GetAttrTest.php b/test/Twig/Tests/Node/Expression/GetAttrTest.php index c9700a9..e72180e 100644 --- a/test/Twig/Tests/Node/Expression/GetAttrTest.php +++ b/test/Twig/Tests/Node/Expression/GetAttrTest.php @@ -26,10 +26,10 @@ class Twig_Tests_Node_Expression_GetAttrTest extends Twig_Tests_Node_TestCase )); $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Node_Expression_GetAttr::TYPE_ARRAY, 0); - $this->assertEquals($expr, $node->node); - $this->assertEquals($attr, $node->attribute); - $this->assertEquals($args, $node->arguments); - $this->assertEquals(Twig_Node_Expression_GetAttr::TYPE_ARRAY, $node['type']); + $this->assertEquals($expr, $node->getNode('node')); + $this->assertEquals($attr, $node->getNode('attribute')); + $this->assertEquals($args, $node->getNode('arguments')); + $this->assertEquals(Twig_Node_Expression_GetAttr::TYPE_ARRAY, $node->getAttribute('type')); } /** diff --git a/test/Twig/Tests/Node/Expression/NameTest.php b/test/Twig/Tests/Node/Expression/NameTest.php index b5345a7..3d8e03a 100644 --- a/test/Twig/Tests/Node/Expression/NameTest.php +++ b/test/Twig/Tests/Node/Expression/NameTest.php @@ -20,7 +20,7 @@ class Twig_Tests_Node_Expression_NameTest extends Twig_Tests_Node_TestCase { $node = new Twig_Node_Expression_Name('foo', 0); - $this->assertEquals('foo', $node['name']); + $this->assertEquals('foo', $node->getAttribute('name')); } /** diff --git a/test/Twig/Tests/Node/Expression/Unary/NegTest.php b/test/Twig/Tests/Node/Expression/Unary/NegTest.php index b53e59a..218de6e 100644 --- a/test/Twig/Tests/Node/Expression/Unary/NegTest.php +++ b/test/Twig/Tests/Node/Expression/Unary/NegTest.php @@ -21,7 +21,7 @@ class Twig_Tests_Node_Expression_Unary_NegTest extends Twig_Tests_Node_TestCase $expr = new Twig_Node_Expression_Constant(1, 0); $node = new Twig_Node_Expression_Unary_Neg($expr, 0); - $this->assertEquals($expr, $node->node); + $this->assertEquals($expr, $node->getNode('node')); } /** diff --git a/test/Twig/Tests/Node/Expression/Unary/NotTest.php b/test/Twig/Tests/Node/Expression/Unary/NotTest.php index e5bcb54..ed6349c 100644 --- a/test/Twig/Tests/Node/Expression/Unary/NotTest.php +++ b/test/Twig/Tests/Node/Expression/Unary/NotTest.php @@ -21,7 +21,7 @@ class Twig_Tests_Node_Expression_Unary_NotTest extends Twig_Tests_Node_TestCase $expr = new Twig_Node_Expression_Constant(1, 0); $node = new Twig_Node_Expression_Unary_Not($expr, 0); - $this->assertEquals($expr, $node->node); + $this->assertEquals($expr, $node->getNode('node')); } /** diff --git a/test/Twig/Tests/Node/Expression/Unary/PosTest.php b/test/Twig/Tests/Node/Expression/Unary/PosTest.php index bb4815c..6a414bc 100644 --- a/test/Twig/Tests/Node/Expression/Unary/PosTest.php +++ b/test/Twig/Tests/Node/Expression/Unary/PosTest.php @@ -21,7 +21,7 @@ class Twig_Tests_Node_Expression_Unary_PosTest extends Twig_Tests_Node_TestCase $expr = new Twig_Node_Expression_Constant(1, 0); $node = new Twig_Node_Expression_Unary_Pos($expr, 0); - $this->assertEquals($expr, $node->node); + $this->assertEquals($expr, $node->getNode('node')); } /** diff --git a/test/Twig/Tests/Node/ForTest.php b/test/Twig/Tests/Node/ForTest.php index aef6ecd..d99109f 100644 --- a/test/Twig/Tests/Node/ForTest.php +++ b/test/Twig/Tests/Node/ForTest.php @@ -26,17 +26,17 @@ class Twig_Tests_Node_ForTest extends Twig_Tests_Node_TestCase $withLoop = false; $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, $withLoop, 0); - $this->assertEquals($keyTarget, $node->key_target); - $this->assertEquals($valueTarget, $node->value_target); - $this->assertEquals($seq, $node->seq); - $this->assertEquals($body, $node->body); - $this->assertEquals(null, $node->else); + $this->assertEquals($keyTarget, $node->getNode('key_target')); + $this->assertEquals($valueTarget, $node->getNode('value_target')); + $this->assertEquals($seq, $node->getNode('seq')); + $this->assertEquals($body, $node->getNode('body')); + $this->assertEquals(null, $node->getNode('else')); - $this->assertEquals($withLoop, $node['with_loop']); + $this->assertEquals($withLoop, $node->getAttribute('with_loop')); $else = new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 0), 0); $node = new Twig_Node_For($keyTarget, $valueTarget, $seq, $body, $else, $withLoop, 0); - $this->assertEquals($else, $node->else); + $this->assertEquals($else, $node->getNode('else')); } /** diff --git a/test/Twig/Tests/Node/IfTest.php b/test/Twig/Tests/Node/IfTest.php index 8569474..ff252b5 100644 --- a/test/Twig/Tests/Node/IfTest.php +++ b/test/Twig/Tests/Node/IfTest.php @@ -25,12 +25,12 @@ class Twig_Tests_Node_IfTest extends Twig_Tests_Node_TestCase $else = null; $node = new Twig_Node_If($t, $else, 0); - $this->assertEquals($t, $node->tests); - $this->assertEquals(null, $node->else); + $this->assertEquals($t, $node->getNode('tests')); + $this->assertEquals(null, $node->getNode('else')); $else = new Twig_Node_Print(new Twig_Node_Expression_Name('bar', 0), 0); $node = new Twig_Node_If($t, $else, 0); - $this->assertEquals($else, $node->else); + $this->assertEquals($else, $node->getNode('else')); } /** diff --git a/test/Twig/Tests/Node/ImportTest.php b/test/Twig/Tests/Node/ImportTest.php index 5d4b200..84dc16d 100644 --- a/test/Twig/Tests/Node/ImportTest.php +++ b/test/Twig/Tests/Node/ImportTest.php @@ -22,8 +22,8 @@ class Twig_Tests_Node_ImportTest extends Twig_Tests_Node_TestCase $var = new Twig_Node_Expression_AssignName('macro', 0); $node = new Twig_Node_Import($macro, $var, 0); - $this->assertEquals($macro, $node->expr); - $this->assertEquals($var, $node->var); + $this->assertEquals($macro, $node->getNode('expr')); + $this->assertEquals($var, $node->getNode('var')); } /** diff --git a/test/Twig/Tests/Node/IncludeTest.php b/test/Twig/Tests/Node/IncludeTest.php index b25b30a..e6ccb55 100644 --- a/test/Twig/Tests/Node/IncludeTest.php +++ b/test/Twig/Tests/Node/IncludeTest.php @@ -21,12 +21,12 @@ class Twig_Tests_Node_IncludeTest extends Twig_Tests_Node_TestCase $expr = new Twig_Node_Expression_Constant('foo.twig', 0); $node = new Twig_Node_Include($expr, null, 0); - $this->assertEquals(null, $node->variables); - $this->assertEquals($expr, $node->expr); + $this->assertEquals(null, $node->getNode('variables')); + $this->assertEquals($expr, $node->getNode('expr')); $vars = new Twig_Node_Expression_Array(array('foo' => new Twig_Node_Expression_Constant(true, 0)), 0); $node = new Twig_Node_Include($expr, $vars, 0); - $this->assertEquals($vars, $node->variables); + $this->assertEquals($vars, $node->getNode('variables')); } /** diff --git a/test/Twig/Tests/Node/MacroTest.php b/test/Twig/Tests/Node/MacroTest.php index 959d016..4a1e1ca 100644 --- a/test/Twig/Tests/Node/MacroTest.php +++ b/test/Twig/Tests/Node/MacroTest.php @@ -22,9 +22,9 @@ class Twig_Tests_Node_MacroTest extends Twig_Tests_Node_TestCase $arguments = new Twig_Node(array(new Twig_Node_Expression_Name('foo', 0)), array(), 0); $node = new Twig_Node_Macro('foo', $body, $arguments, 0); - $this->assertEquals($body, $node->body); - $this->assertEquals($arguments, $node->arguments); - $this->assertEquals('foo', $node['name']); + $this->assertEquals($body, $node->getNode('body')); + $this->assertEquals($arguments, $node->getNode('arguments')); + $this->assertEquals('foo', $node->getAttribute('name')); } /** diff --git a/test/Twig/Tests/Node/ModuleTest.php b/test/Twig/Tests/Node/ModuleTest.php index b52308b..9c2bd88 100644 --- a/test/Twig/Tests/Node/ModuleTest.php +++ b/test/Twig/Tests/Node/ModuleTest.php @@ -25,11 +25,11 @@ class Twig_Tests_Node_ModuleTest extends Twig_Tests_Node_TestCase $filename = 'foo.twig'; $node = new Twig_Node_Module($body, $parent, $blocks, $macros, $filename); - $this->assertEquals($body, $node->body); - $this->assertEquals($blocks, $node->blocks); - $this->assertEquals($macros, $node->macros); - $this->assertEquals($parent, $node->parent); - $this->assertEquals($filename, $node['filename']); + $this->assertEquals($body, $node->getNode('body')); + $this->assertEquals($blocks, $node->getNode('blocks')); + $this->assertEquals($macros, $node->getNode('macros')); + $this->assertEquals($parent, $node->getNode('parent')); + $this->assertEquals($filename, $node->getAttribute('filename')); } /** diff --git a/test/Twig/Tests/Node/ParentTest.php b/test/Twig/Tests/Node/ParentTest.php index 6b40b24..f239ef4 100644 --- a/test/Twig/Tests/Node/ParentTest.php +++ b/test/Twig/Tests/Node/ParentTest.php @@ -20,7 +20,7 @@ class Twig_Tests_Node_ParentTest extends Twig_Tests_Node_TestCase { $node = new Twig_Node_Parent('foo', 0); - $this->assertEquals('foo', $node['name']); + $this->assertEquals('foo', $node->getAttribute('name')); } /** diff --git a/test/Twig/Tests/Node/PrintTest.php b/test/Twig/Tests/Node/PrintTest.php index 53ef15e..168663c 100644 --- a/test/Twig/Tests/Node/PrintTest.php +++ b/test/Twig/Tests/Node/PrintTest.php @@ -21,7 +21,7 @@ class Twig_Tests_Node_PrintTest extends Twig_Tests_Node_TestCase $expr = new Twig_Node_Expression_Constant('foo', 0); $node = new Twig_Node_Print($expr, 0); - $this->assertEquals($expr, $node->expr); + $this->assertEquals($expr, $node->getNode('expr')); } /** diff --git a/test/Twig/Tests/Node/SandboxTest.php b/test/Twig/Tests/Node/SandboxTest.php index d3598a9..1610873 100644 --- a/test/Twig/Tests/Node/SandboxTest.php +++ b/test/Twig/Tests/Node/SandboxTest.php @@ -21,7 +21,7 @@ class Twig_Tests_Node_SandboxTest extends Twig_Tests_Node_TestCase $body = new Twig_Node_Text('foo', 0); $node = new Twig_Node_Sandbox($body, 0); - $this->assertEquals($body, $node->body); + $this->assertEquals($body, $node->getNode('body')); } /** diff --git a/test/Twig/Tests/Node/SandboxedModuleTest.php b/test/Twig/Tests/Node/SandboxedModuleTest.php index 4551133..91e54ae 100644 --- a/test/Twig/Tests/Node/SandboxedModuleTest.php +++ b/test/Twig/Tests/Node/SandboxedModuleTest.php @@ -26,11 +26,11 @@ class Twig_Tests_Node_SandboxedModuleTest extends Twig_Tests_Node_TestCase $node = new Twig_Node_Module($body, $parent, $blocks, $macros, $filename); $node = new Twig_Node_SandboxedModule($node, array('for'), array('upper')); - $this->assertEquals($body, $node->body); - $this->assertEquals($blocks, $node->blocks); - $this->assertEquals($macros, $node->macros); - $this->assertEquals($parent, $node->parent); - $this->assertEquals($filename, $node['filename']); + $this->assertEquals($body, $node->getNode('body')); + $this->assertEquals($blocks, $node->getNode('blocks')); + $this->assertEquals($macros, $node->getNode('macros')); + $this->assertEquals($parent, $node->getNode('parent')); + $this->assertEquals($filename, $node->getAttribute('filename')); } /** diff --git a/test/Twig/Tests/Node/SandboxedPrintTest.php b/test/Twig/Tests/Node/SandboxedPrintTest.php index ee205a6..a326005 100644 --- a/test/Twig/Tests/Node/SandboxedPrintTest.php +++ b/test/Twig/Tests/Node/SandboxedPrintTest.php @@ -22,7 +22,7 @@ class Twig_Tests_Node_SandboxedPrintTest extends Twig_Tests_Node_TestCase $node = new Twig_Node_Print($expr, 0); $node = new Twig_Node_SandboxedPrint($node); - $this->assertEquals($expr, $node->expr); + $this->assertEquals($expr, $node->getNode('expr')); } /** diff --git a/test/Twig/Tests/Node/SetTest.php b/test/Twig/Tests/Node/SetTest.php index 4c83b63..7883fba 100644 --- a/test/Twig/Tests/Node/SetTest.php +++ b/test/Twig/Tests/Node/SetTest.php @@ -22,9 +22,9 @@ class Twig_Tests_Node_SetTest extends Twig_Tests_Node_TestCase $values = new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 0)), array(), 0); $node = new Twig_Node_Set(false, $names, $values, 0); - $this->assertEquals($names, $node->names); - $this->assertEquals($values, $node->values); - $this->assertEquals(false, $node['capture']); + $this->assertEquals($names, $node->getNode('names')); + $this->assertEquals($values, $node->getNode('values')); + $this->assertEquals(false, $node->getAttribute('capture')); } /** diff --git a/test/Twig/Tests/Node/TextTest.php b/test/Twig/Tests/Node/TextTest.php index 8550d6f..87e0337 100644 --- a/test/Twig/Tests/Node/TextTest.php +++ b/test/Twig/Tests/Node/TextTest.php @@ -20,7 +20,7 @@ class Twig_Tests_Node_TextTest extends Twig_Tests_Node_TestCase { $node = new Twig_Node_Text('foo', 0); - $this->assertEquals('foo', $node['data']); + $this->assertEquals('foo', $node->getAttribute('data')); } /** diff --git a/test/Twig/Tests/Node/TransTest.php b/test/Twig/Tests/Node/TransTest.php index e7e598e..962b4d3 100644 --- a/test/Twig/Tests/Node/TransTest.php +++ b/test/Twig/Tests/Node/TransTest.php @@ -31,9 +31,9 @@ class Twig_Tests_Node_TransTest extends Twig_Tests_Node_TestCase ), array(), 0); $node = new Twig_Node_Trans($body, $plural, $count, 0); - $this->assertEquals($body, $node->body); - $this->assertEquals($count, $node->count); - $this->assertEquals($plural, $node->plural); + $this->assertEquals($body, $node->getNode('body')); + $this->assertEquals($count, $node->getNode('count')); + $this->assertEquals($plural, $node->getNode('plural')); } public function getTests() -- 1.7.2.5