[TwigBundle] optimized calls to helpers
This commit is contained in:
parent
3ce8ad1718
commit
416bd7872e
53
src/Symfony/Bundle/TwigBundle/Node/HelperNode.php
Normal file
53
src/Symfony/Bundle/TwigBundle/Node/HelperNode.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Bundle\TwigBundle\Node;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*/
|
||||
class HelperNode extends \Twig_Node
|
||||
{
|
||||
public function __construct($helper, $method, \Twig_Node_Expression_Array $values, $lineno, $tag = null)
|
||||
{
|
||||
parent::__construct(array('values' => $values), array('helper' => $helper, 'method' => $method), $lineno, $tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles the node to PHP.
|
||||
*
|
||||
* @param \Twig_Compiler A Twig_Compiler instance
|
||||
*/
|
||||
public function compile($compiler)
|
||||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->raw("\$this->env->getExtension(")
|
||||
->string('symfony.helpers')
|
||||
->raw(")->getContainer()->get(")
|
||||
->string($this['helper'])
|
||||
->raw(")->")
|
||||
->raw($this['method'])
|
||||
->raw("(")
|
||||
;
|
||||
|
||||
foreach ($this->values as $i => $value) {
|
||||
$compiler->subcompile($value);
|
||||
if ($i !== count($this->values) - 1) {
|
||||
$compiler->raw(', ');
|
||||
}
|
||||
}
|
||||
|
||||
$compiler->raw(")");
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace Symfony\Bundle\TwigBundle\TokenParser;
|
||||
|
||||
use Symfony\Bundle\TwigBundle\Node\HelperNode;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
@ -55,16 +57,7 @@ class HelperTokenParser extends \Twig_SimpleTokenParser
|
||||
{
|
||||
return $this->output(
|
||||
$this->markAsSafe(
|
||||
$this->call(
|
||||
$this->call(
|
||||
$this->call(new \Twig_Node_Expression_ExtensionReference('symfony.helpers', 0), 'getContainer'),
|
||||
'get',
|
||||
array(new \Twig_Node_Expression_Constant($this->helper, 0))
|
||||
),
|
||||
$this->method,
|
||||
$this->getNodeValues($values)
|
||||
)
|
||||
)
|
||||
);
|
||||
new HelperNode($this->helper, $this->method, new \Twig_Node_Expression_Array($this->getNodeValues($values), $line), $line)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user