-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFeatureTagNode.php
53 lines (49 loc) · 1.29 KB
/
FeatureTagNode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Unleash\Client\Bundle\Twig;
use Twig\Compiler;
use Twig\Node\Node;
final class FeatureTagNode extends Node
{
/**
* @readonly
* @var string
*/
private $featureName;
/**
* @readonly
* @var \Twig\Node\Node
*/
private $content;
/**
* @readonly
* @var string
*/
private $extensionClass;
public function __construct(
string $featureName,
Node $content,
int $line,
string $tag,
string $extensionClass
) {
$this->featureName = $featureName;
$this->content = $content;
$this->extensionClass = $extensionClass;
parent::__construct([], [], $line, $tag);
}
public function compile(Compiler $compiler): void
{
$compiler
->addDebugInfo($this)
->write("if (\$this->extensions['{$this->extensionClass}']->isEnabled('{$this->featureName}')) {")
->raw(PHP_EOL)
->indent()
->write("\$context['variant'] = \$this->extensions['{$this->extensionClass}']->getVariant('{$this->featureName}');")
->subcompile($this->content)
->write("unset(\$context['variant']);")
->raw(PHP_EOL)
->indent(-1)
->write('}')
->raw(PHP_EOL);
}
}