Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 416bd78

Browse filesBrowse files
committed
[TwigBundle] optimized calls to helpers
1 parent 3ce8ad1 commit 416bd78
Copy full SHA for 416bd78

File tree

Expand file treeCollapse file tree

2 files changed

+57
-11
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+57
-11
lines changed
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\TwigBundle\Node;
4+
5+
/*
6+
* This file is part of the Symfony package.
7+
*
8+
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
/**
15+
*
16+
*
17+
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
18+
*/
19+
class HelperNode extends \Twig_Node
20+
{
21+
public function __construct($helper, $method, \Twig_Node_Expression_Array $values, $lineno, $tag = null)
22+
{
23+
parent::__construct(array('values' => $values), array('helper' => $helper, 'method' => $method), $lineno, $tag);
24+
}
25+
26+
/**
27+
* Compiles the node to PHP.
28+
*
29+
* @param \Twig_Compiler A Twig_Compiler instance
30+
*/
31+
public function compile($compiler)
32+
{
33+
$compiler
34+
->addDebugInfo($this)
35+
->raw("\$this->env->getExtension(")
36+
->string('symfony.helpers')
37+
->raw(")->getContainer()->get(")
38+
->string($this['helper'])
39+
->raw(")->")
40+
->raw($this['method'])
41+
->raw("(")
42+
;
43+
44+
foreach ($this->values as $i => $value) {
45+
$compiler->subcompile($value);
46+
if ($i !== count($this->values) - 1) {
47+
$compiler->raw(', ');
48+
}
49+
}
50+
51+
$compiler->raw(")");
52+
}
53+
}

‎src/Symfony/Bundle/TwigBundle/TokenParser/HelperTokenParser.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/TokenParser/HelperTokenParser.php
+4-11Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Symfony\Bundle\TwigBundle\TokenParser;
44

5+
use Symfony\Bundle\TwigBundle\Node\HelperNode;
6+
57
/*
68
* This file is part of the Symfony package.
79
*
@@ -55,16 +57,7 @@ protected function getNode(array $values, $line)
5557
{
5658
return $this->output(
5759
$this->markAsSafe(
58-
$this->call(
59-
$this->call(
60-
$this->call(new \Twig_Node_Expression_ExtensionReference('symfony.helpers', 0), 'getContainer'),
61-
'get',
62-
array(new \Twig_Node_Expression_Constant($this->helper, 0))
63-
),
64-
$this->method,
65-
$this->getNodeValues($values)
66-
)
67-
)
68-
);
60+
new HelperNode($this->helper, $this->method, new \Twig_Node_Expression_Array($this->getNodeValues($values), $line), $line)
61+
));
6962
}
7063
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.