|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of Twig. |
|
|
5 |
* |
|
|
6 |
* (c) 2009 Fabien Potencier |
|
|
7 |
* (c) 2009 Armin Ronacher |
|
|
8 |
* |
|
|
9 |
* For the full copyright and license information, please view the LICENSE |
|
|
10 |
* file that was distributed with this source code. |
|
|
11 |
*/ |
|
|
12 |
class Twig_Node_Expression_Name extends Twig_Node_Expression |
|
|
13 |
{ |
|
|
14 |
public function __construct($name, $lineno) |
|
|
15 |
{ |
|
|
16 |
parent::__construct(array(), array('name' => $name), $lineno); |
|
|
17 |
} |
|
|
18 |
|
|
|
19 |
public function compile(Twig_Compiler $compiler) |
|
|
20 |
{ |
|
|
21 |
static $specialVars = array( |
|
|
22 |
'_self' => '$this', |
|
|
23 |
'_context' => '$context', |
|
|
24 |
'_charset' => '$this->env->getCharset()', |
|
|
25 |
); |
|
|
26 |
|
|
|
27 |
$name = $this->getAttribute('name'); |
|
|
28 |
|
|
|
29 |
if ($this->hasAttribute('is_defined_test')) { |
|
|
30 |
if (isset($specialVars[$name])) { |
|
|
31 |
$compiler->repr(true); |
|
|
32 |
} else { |
|
|
33 |
$compiler->raw('array_key_exists(')->repr($name)->raw(', $context)'); |
|
|
34 |
} |
|
|
35 |
} elseif (isset($specialVars[$name])) { |
|
|
36 |
$compiler->raw($specialVars[$name]); |
|
|
37 |
} else { |
|
|
38 |
$compiler->raw(sprintf('$this->getContext($context, \'%s\')', $name)); |
|
|
39 |
} |
|
|
40 |
} |
|
|
41 |
} |