Line | |
---|
1 | <?php |
---|
2 | |
---|
3 | /* |
---|
4 | * This file is part of Twig. |
---|
5 | * |
---|
6 | * (c) 2010 Fabien Potencier |
---|
7 | * |
---|
8 | * For the full copyright and license information, please view the LICENSE |
---|
9 | * file that was distributed with this source code. |
---|
10 | */ |
---|
11 | class Twig_Node_Expression_Function extends Twig_Node_Expression |
---|
12 | { |
---|
13 | public function __construct(Twig_Node_Expression_Name $name, Twig_NodeInterface $arguments, $lineno) |
---|
14 | { |
---|
15 | parent::__construct(array('name' => $name, 'arguments' => $arguments), array(), $lineno); |
---|
16 | } |
---|
17 | |
---|
18 | public function compile(Twig_Compiler $compiler) |
---|
19 | { |
---|
20 | $function = $compiler->getEnvironment()->getFunction($this->getNode('name')->getAttribute('name')); |
---|
21 | if (false === $function) { |
---|
22 | throw new Twig_Error_Syntax(sprintf('The function "%s" does not exist', $this->getNode('name')->getAttribute('name')), $this->getLine()); |
---|
23 | } |
---|
24 | |
---|
25 | $compiler |
---|
26 | ->raw($function->compile().'(') |
---|
27 | ->raw($function->needsEnvironment() ? '$this->env' : '') |
---|
28 | ; |
---|
29 | |
---|
30 | if ($function->needsContext()) { |
---|
31 | $compiler->raw($function->needsEnvironment() ? ', $context' : '$context'); |
---|
32 | } |
---|
33 | |
---|
34 | $first = true; |
---|
35 | foreach ($this->getNode('arguments') as $node) { |
---|
36 | if (!$first) { |
---|
37 | $compiler->raw(', '); |
---|
38 | } else { |
---|
39 | if ($function->needsEnvironment() || $function->needsContext()) { |
---|
40 | $compiler->raw(', '); |
---|
41 | } |
---|
42 | $first = false; |
---|
43 | } |
---|
44 | $compiler->subcompile($node); |
---|
45 | } |
---|
46 | |
---|
47 | $compiler->raw(')'); |
---|
48 | } |
---|
49 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.