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