1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* This file is part of TwigView. |
6
|
|
|
* |
7
|
|
|
** (c) 2014 Cees-Jan Kiewiet |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace WyriHaximus\TwigView\Lib\Twig\Node; |
14
|
|
|
|
15
|
|
|
use Twig\Compiler; |
16
|
|
|
use Twig\Node\Expression\AbstractExpression; |
17
|
|
|
use Twig\Node\Expression\ArrayExpression; |
18
|
|
|
use Twig\Node\Node; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class Element. |
22
|
|
|
* @package WyriHaximus\TwigView\Lib\Twig\Node |
23
|
|
|
*/ |
24
|
|
|
final class Element extends Node |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Constructor. |
28
|
|
|
* |
29
|
|
|
* @param \Twig\Node\Expression\AbstractExpression $name Name. |
30
|
|
|
* @param \Twig\Node\Expression\AbstractExpression $data Data. |
31
|
|
|
* @param \Twig\Node\Expression\AbstractExpression $options Options. |
32
|
|
|
* @param int $lineno Linenumber. |
33
|
|
|
* @param string $tag Tag. |
34
|
|
|
*/ |
35
|
|
|
public function __construct( |
36
|
|
|
AbstractExpression $name, |
37
|
|
|
?AbstractExpression $data = null, |
38
|
|
|
?AbstractExpression $options = null, |
39
|
|
|
int $lineno = 0, |
40
|
|
|
?string $tag = null |
41
|
|
|
) { |
42
|
|
|
if ($data === null) { |
43
|
|
|
$data = new ArrayExpression([], $lineno); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if ($options === null) { |
47
|
|
|
$options = new ArrayExpression([], $lineno); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
parent::__construct( |
51
|
|
|
[ |
52
|
|
|
'name' => $name, |
53
|
|
|
'data' => $data, |
54
|
|
|
'options' => $options, |
55
|
|
|
], |
56
|
|
|
[], |
57
|
|
|
$lineno, |
58
|
|
|
$tag |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Compile node. |
64
|
|
|
* |
65
|
|
|
* @param \Twig\Compiler $compiler Compiler. |
66
|
|
|
* |
67
|
|
|
*/ |
68
|
|
|
public function compile(Compiler $compiler) |
69
|
|
|
{ |
70
|
|
|
$compiler->addDebugInfo($this); |
71
|
|
|
|
72
|
|
|
$compiler->raw('echo $context[\'_view\']->element('); |
73
|
|
|
$compiler->subcompile($this->getNode('name')); |
74
|
|
|
$data = $this->getNode('data'); |
75
|
|
|
if ($data !== null) { |
76
|
|
|
$compiler->raw(','); |
77
|
|
|
$compiler->subcompile($data); |
78
|
|
|
} |
79
|
|
|
$options = $this->getNode('options'); |
80
|
|
|
if ($options !== null) { |
81
|
|
|
$compiler->raw(','); |
82
|
|
|
$compiler->subcompile($options); |
83
|
|
|
} |
84
|
|
|
$compiler->raw(");\n"); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|