}
/**
+ * Gets the template class prefix.
+ *
+ * @return string The template class prefix
+ */
+ public function getTemplateClassPrefix()
+ {
+ return $this->templateClassPrefix;
+ }
+
+ /**
* Loads a template by name.
*
* @param string $name The template name
+++ /dev/null
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) 2010 Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Represents a from node.
- *
- * @package twig
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
-class Twig_Node_From extends Twig_Node_Import
-{
- public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null)
- {
- parent::__construct($expr, new Twig_Node_Expression_AssignName(str_replace('.', '_', uniqid('_imported_', true)), $lineno), $lineno, $tag);
- }
-}
protected $env;
protected $reservedMacroNames;
protected $importedFunctions;
+ protected $tmpVarCount;
/**
* Constructor.
$this->env = $env;
}
+ public function getVarName()
+ {
+ return sprintf('__internal_%s_%d', substr($this->env->getTemplateClass($this->stream->getFilename()), strlen($this->env->getTemplateClassPrefix())), ++$this->tmpVarCount);
+ }
+
/**
* Converts a token stream to a node tree.
*
*/
public function parse(Twig_TokenStream $stream)
{
+ $this->tmpVarCount = 0;
+
// tag handlers
$this->handlers = $this->env->getTokenParsers();
$this->handlers->setParser($this);
*/
public function parse(Twig_Token $token)
{
- $name = str_replace('.', '_', uniqid('_tmp_', true));
+ $name = $this->parser->getVarName();
$ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), $token->getLine(), $this->getTag());
$filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
$stream->expect(Twig_Token::BLOCK_END_TYPE);
- $node = new Twig_Node_From($macro, $token->getLine(), $this->getTag());
+ $node = new Twig_Node_Import($macro, new Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag());
foreach($targets as $name => $alias) {
$this->parser->addImportedFunction($alias, $name, $node->getNode('var'));