1 | <?php |
||
2 | /** |
||
3 | * Twig Profiler plugin for Craft CMS |
||
4 | * |
||
5 | * Twig Profiler allows you to profile sections of your Twig templates, and see |
||
6 | * the resulting timings in the Yii2 Debug Toolbar |
||
7 | * |
||
8 | * @link https://nystudio107.com/ |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
9 | * @copyright Copyright (c) nystudio107 |
||
0 ignored issues
–
show
|
|||
10 | */ |
||
0 ignored issues
–
show
|
|||
11 | |||
12 | namespace nystudio107\twigprofiler\twigextensions; |
||
13 | |||
14 | use Twig\Token; |
||
15 | use Twig\TokenParser\AbstractTokenParser; |
||
16 | |||
17 | /** |
||
18 | * Class ProfilerTokenParser |
||
19 | * |
||
20 | * @author nystudio107 |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||
21 | * @package TwigProfiler |
||
0 ignored issues
–
show
|
|||
22 | * @since 1.0.1 |
||
0 ignored issues
–
show
|
|||
23 | */ |
||
0 ignored issues
–
show
|
|||
24 | class ProfilerTokenParser extends AbstractTokenParser |
||
25 | { |
||
26 | // Public Methods |
||
27 | // ========================================================================= |
||
28 | |||
29 | /** |
||
0 ignored issues
–
show
|
|||
30 | * @inheritdoc |
||
31 | */ |
||
0 ignored issues
–
show
|
|||
32 | public function getTag(): string |
||
33 | { |
||
34 | return 'profile'; |
||
35 | } |
||
36 | |||
37 | /** |
||
0 ignored issues
–
show
|
|||
38 | * @inheritdoc |
||
39 | */ |
||
0 ignored issues
–
show
|
|||
40 | public function parse(Token $token): ProfilerNode |
||
41 | { |
||
42 | $lineno = $token->getLine(); |
||
43 | $stream = $this->parser->getStream(); |
||
44 | $nodes = [ |
||
45 | 'profile' => $this->parser->getExpressionParser()->parseExpression(), |
||
46 | ]; |
||
47 | $stream->expect(Token::BLOCK_END_TYPE); |
||
48 | $nodes['body'] = $this->parser->subparse(fn(Token $token): bool => $this->decideProfilerEnd($token), true); |
||
49 | $stream->expect(Token::BLOCK_END_TYPE); |
||
50 | |||
51 | return new ProfilerNode($nodes, [], $lineno, $this->getTag()); |
||
52 | } |
||
53 | |||
54 | public function decideProfilerEnd(Token $token): bool |
||
0 ignored issues
–
show
|
|||
55 | { |
||
56 | return $token->test('endprofile'); |
||
57 | } |
||
58 | } |
||
59 |