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 nystudio107\twigprofiler\TwigProfiler; |
||
15 | use Twig\Compiler; |
||
16 | use Twig\Node\Node; |
||
17 | |||
18 | /** |
||
19 | * Class ProfilerTokenParser |
||
20 | * |
||
21 | * @author nystudio107 |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||
22 | * @package TwigProfiler |
||
0 ignored issues
–
show
|
|||
23 | * @since 1.0.1 |
||
0 ignored issues
–
show
|
|||
24 | */ |
||
0 ignored issues
–
show
|
|||
25 | class ProfilerNode extends Node |
||
26 | { |
||
27 | // Public Methods |
||
28 | // ========================================================================= |
||
29 | |||
30 | /** |
||
0 ignored issues
–
show
|
|||
31 | * @inheritdoc |
||
32 | */ |
||
0 ignored issues
–
show
|
|||
33 | public function compile(Compiler $compiler): void |
||
34 | { |
||
35 | $profileName = $this->getNode('profile'); |
||
36 | if ($profileName !== null) { |
||
37 | $profileName = $profileName->attributes['value'] ?? ''; |
||
38 | if (!empty($profileName)) { |
||
39 | $compiler |
||
40 | ->addDebugInfo($this) |
||
41 | ->write(TwigProfiler::class . "::\$plugin->profile->begin('" . $profileName . "');\n") |
||
42 | ->indent() |
||
43 | ->subcompile($this->getNode('body')) |
||
44 | ->outdent() |
||
45 | ->write(TwigProfiler::class . "::\$plugin->profile->end('" . $profileName . "');\n"); |
||
46 | } |
||
47 | } |
||
48 | } |
||
49 | } |
||
50 |