made the parsing independent of the template loaders

This basically reverts 57ff88255e
This commit is contained in:
Fabien Potencier
2012-07-10 18:30:12 +02:00
parent 584a1a30b9
commit 611f4451e3
3 changed files with 22 additions and 4 deletions
+1
View File
@@ -1,5 +1,6 @@
* 1.9.0 (2012-XX-XX)
* made the parsing independent of the template loaders
* fixed exception trace when an error occurs when rendering a child template
* added escaping strategies for CSS, URL, and HTML attributes
* fixed nested embed tag calls
+1 -4
View File
@@ -30,7 +30,6 @@ class Twig_Parser implements Twig_ParserInterface
protected $env;
protected $reservedMacroNames;
protected $importedFunctions;
protected $tmpVarCount;
protected $traits;
protected $embeddedTemplates = array();
@@ -51,7 +50,7 @@ class Twig_Parser implements Twig_ParserInterface
public function getVarName()
{
return sprintf('__internal_%s_%d', substr($this->env->getTemplateClass($this->stream->getFilename()), strlen($this->env->getTemplateClassPrefix())), ++$this->tmpVarCount);
return sprintf('__internal_%s', hash('sha1', uniqid(mt_rand(), true), false));
}
/**
@@ -68,8 +67,6 @@ class Twig_Parser implements Twig_ParserInterface
unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser']);
$this->stack[] = $vars;
$this->tmpVarCount = 0;
// tag handlers
if (null === $this->handlers) {
$this->handlers = $this->env->getTokenParsers();
+20
View File
@@ -115,6 +115,26 @@ class Twig_Tests_ParserTest extends PHPUnit_Framework_TestCase
$this->assertEquals(null, $parser->getParent());
}
// The getVarName() must not depend on the template loaders,
// If this test does not throw any exception, that's good.
// see https://github.com/symfony/symfony/issues/4218
public function testGetVarName()
{
$twig = new Twig_Environment(null, array(
'autoescape' => false,
'optimizations' => 0,
));
$twig->parse($twig->tokenize(<<<EOF
{% from _self import foo %}
{% macro foo() %}
{{ foo }}
{% endmacro %}
EOF
));
}
protected function getParserForFilterBodyNodes()
{
$parser = new TestParser(new Twig_Environment());