-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFeatureTagNode.php
35 lines (31 loc) · 1008 Bytes
/
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
<?php
namespace Unleash\Client\Bundle\Twig;
use Twig\Compiler;
use Twig\Node\Node;
final class FeatureTagNode extends Node
{
public function __construct(
private readonly string $featureName,
private readonly Node $content,
int $line,
string $tag,
private readonly string $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);
}
}