|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ae\FeatureBundle\Twig\Node; |
|
4
|
|
|
|
|
5
|
|
|
use Ae\FeatureBundle\Twig\Extension\FeatureExtension; |
|
6
|
|
|
use Twig_Compiler; |
|
7
|
|
|
use Twig_Environment; |
|
8
|
|
|
use Twig_Node; |
|
9
|
|
|
use Twig_Node_Expression; |
|
10
|
|
|
use Twig_Node_Expression_Array; |
|
11
|
|
|
use Twig_Node_Expression_Constant; |
|
12
|
|
|
use Twig_Node_Expression_MethodCall; |
|
13
|
|
|
use Twig_Node_If; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @author Carlo Forghieri <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class FeatureNode extends Twig_Node_If |
|
19
|
|
|
{ |
|
20
|
3 |
|
public function __construct($name, $parent, $body, $else, $lineno, $tag = null) |
|
21
|
|
|
{ |
|
22
|
3 |
|
$tests = new Twig_Node([ |
|
23
|
3 |
|
$this->createExpression($name, $parent, $lineno), |
|
24
|
3 |
|
$body, |
|
25
|
|
|
]); |
|
26
|
|
|
|
|
27
|
3 |
|
parent::__construct($tests, $else, $lineno, $tag); |
|
28
|
3 |
|
} |
|
29
|
|
|
|
|
30
|
4 |
|
protected function createExpression($name, $parent, $lineno) |
|
31
|
|
|
{ |
|
32
|
3 |
|
$newName = version_compare(Twig_Environment::VERSION, '1.26.0', '>=') |
|
33
|
3 |
|
? FeatureExtension::class |
|
34
|
3 |
|
: 'feature'; |
|
35
|
|
|
|
|
36
|
3 |
|
return new Twig_Node_Expression_MethodCall( |
|
37
|
|
|
new class([], ['name' => $newName], $lineno) extends Twig_Node_Expression { |
|
38
|
4 |
|
public function compile(Twig_Compiler $compiler) |
|
39
|
|
|
{ |
|
40
|
4 |
|
$compiler->raw(sprintf( |
|
41
|
4 |
|
'$this->env->getExtension(\'%s\')', |
|
42
|
4 |
|
$this->getAttribute('name') |
|
43
|
|
|
)); |
|
44
|
4 |
|
} |
|
45
|
|
|
}, |
|
46
|
3 |
|
'isGranted', |
|
47
|
3 |
|
new Twig_Node_Expression_Array( |
|
48
|
|
|
[ |
|
49
|
3 |
|
new Twig_Node_Expression_Constant('name', $lineno), |
|
50
|
3 |
|
new Twig_Node_Expression_Constant($name, $lineno), |
|
51
|
3 |
|
new Twig_Node_Expression_Constant('parent', $lineno), |
|
52
|
3 |
|
new Twig_Node_Expression_Constant($parent, $lineno), |
|
53
|
|
|
], |
|
54
|
3 |
|
$lineno |
|
55
|
|
|
), |
|
56
|
3 |
|
$lineno |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|