Added nodes representing local variables

Allows to use local PHP variables as temporary variables in compiled
templates
This commit is contained in:
Arnaud Le Blanc
2010-12-23 22:07:22 +01:00
committed by Fabien Potencier
parent d9e2c42e41
commit ad6374434d
2 changed files with 63 additions and 0 deletions
@@ -0,0 +1,23 @@
<?php
/*
* This file is part of Twig.
*
* (c) 2009 Fabien Potencier
* (c) 2010 Arnaud Le Blanc
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Represents a local private variable.
*
* Such variables are not visible from templates.
*
* @package twig
* @author Arnaud Le Blanc <arnaud.lb@gmail.com>
*/
class Twig_Node_Expression_AssignLocalName extends Twig_Node_Expression_LocalName
{
}
+40
View File
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of Twig.
*
* (c) 2009 Fabien Potencier
* (c) 2010 Arnaud Le Blanc
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Represents a local private variable.
*
* Such variables are not visible from templates.
*
* @package twig
* @author Arnaud Le Blanc <arnaud.lb@gmail.com>
*/
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'));
}
}