From ad6374434dc39dd2be747cbc0ce6da8e397ffa6a Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Thu, 23 Dec 2010 22:07:22 +0100 Subject: [PATCH] Added nodes representing local variables Allows to use local PHP variables as temporary variables in compiled templates --- lib/Twig/Node/Expression/AssignLocalName.php | 23 +++++++++++++++ lib/Twig/Node/Expression/LocalName.php | 40 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 0 deletions(-) create mode 100644 lib/Twig/Node/Expression/AssignLocalName.php create mode 100644 lib/Twig/Node/Expression/LocalName.php diff --git a/lib/Twig/Node/Expression/AssignLocalName.php b/lib/Twig/Node/Expression/AssignLocalName.php new file mode 100644 index 0000000..ff9f6a1 --- /dev/null +++ b/lib/Twig/Node/Expression/AssignLocalName.php @@ -0,0 +1,23 @@ + + */ +class Twig_Node_Expression_AssignLocalName extends Twig_Node_Expression_LocalName +{ +} diff --git a/lib/Twig/Node/Expression/LocalName.php b/lib/Twig/Node/Expression/LocalName.php new file mode 100644 index 0000000..0601063 --- /dev/null +++ b/lib/Twig/Node/Expression/LocalName.php @@ -0,0 +1,40 @@ + + */ +class Twig_Node_Expression_LocalName extends Twig_Node_Expression +{ + static protected $counter = 0; + + public function __construct($name = null, $lineno = null) + { + if (null === $name) { + $uniq = self::$counter++; + $name = '__' . $uniq; + } + + parent::__construct(array(), array('name' => $name), $lineno); + } + + public function compile($compiler) + { + $compiler->raw('$' . $this->getAttribute('name')); + } +} + -- 1.7.2.5