Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 57ff882

Browse files
committed
made temporary variable names predictable
1 parent 7cb9159 commit 57ff882

5 files changed

Lines changed: 20 additions & 26 deletions

File tree

lib/Twig/Environment.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,16 @@ public function getTemplateClass($name)
259259
return $this->templateClassPrefix.md5($this->loader->getCacheKey($name));
260260
}
261261

262+
/**
263+
* Gets the template class prefix.
264+
*
265+
* @return string The template class prefix
266+
*/
267+
public function getTemplateClassPrefix()
268+
{
269+
return $this->templateClassPrefix;
270+
}
271+
262272
/**
263273
* Loads a template by name.
264274
*

lib/Twig/Node/From.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

lib/Twig/Parser.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Twig_Parser implements Twig_ParserInterface
2929
protected $env;
3030
protected $reservedMacroNames;
3131
protected $importedFunctions;
32+
protected $tmpVarCount;
3233

3334
/**
3435
* Constructor.
@@ -40,6 +41,11 @@ public function __construct(Twig_Environment $env)
4041
$this->env = $env;
4142
}
4243

44+
public function getVarName()
45+
{
46+
return sprintf('__internal_%s_%d', substr($this->env->getTemplateClass($this->stream->getFilename()), strlen($this->env->getTemplateClassPrefix())), ++$this->tmpVarCount);
47+
}
48+
4349
/**
4450
* Converts a token stream to a node tree.
4551
*
@@ -49,6 +55,8 @@ public function __construct(Twig_Environment $env)
4955
*/
5056
public function parse(Twig_TokenStream $stream)
5157
{
58+
$this->tmpVarCount = 0;
59+
5260
// tag handlers
5361
$this->handlers = $this->env->getTokenParsers();
5462
$this->handlers->setParser($this);

lib/Twig/TokenParser/Filter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Twig_TokenParser_Filter extends Twig_TokenParser
1919
*/
2020
public function parse(Twig_Token $token)
2121
{
22-
$name = str_replace('.', '_', uniqid('_tmp_', true));
22+
$name = $this->parser->getVarName();
2323
$ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), $token->getLine(), $this->getTag());
2424

2525
$filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());

lib/Twig/TokenParser/From.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function parse(Twig_Token $token)
4545

4646
$stream->expect(Twig_Token::BLOCK_END_TYPE);
4747

48-
$node = new Twig_Node_From($macro, $token->getLine(), $this->getTag());
48+
$node = new Twig_Node_Import($macro, new Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag());
4949

5050
foreach($targets as $name => $alias) {
5151
$this->parser->addImportedFunction($alias, $name, $node->getNode('var'));

0 commit comments

Comments
 (0)