-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFeatureTagTokenParser.php
40 lines (34 loc) · 1.05 KB
/
FeatureTagTokenParser.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
<?php
namespace Unleash\Client\Bundle\Twig;
use Twig\Node\Node;
use Twig\Token;
use Twig\TokenParser\AbstractTokenParser;
final class FeatureTagTokenParser extends AbstractTokenParser
{
/**
* @readonly
* @var string
*/
private $extensionClass;
public function __construct(string $extensionClass)
{
$this->extensionClass = $extensionClass;
}
public function parse(Token $token): Node
{
$stream = $this->parser->getStream();
$featureName = $stream->expect(Token::STRING_TYPE)->getValue();
$stream->expect(Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(function (Token $token) {
return $token->test('endfeature');
});
$stream->expect(Token::NAME_TYPE, 'endfeature');
$stream->expect(Token::BLOCK_END_TYPE);
assert(is_string($featureName));
return new FeatureTagNode($featureName, $body, $token->getLine(), $this->getTag(), $this->extensionClass);
}
public function getTag(): string
{
return 'feature';
}
}