1 | <?php |
||
2 | /** |
||
3 | * Template Comments plugin for Craft CMS |
||
4 | * |
||
5 | * Adds a HTML comment to demarcate each Twig template that is included or |
||
6 | * extended. |
||
7 | * |
||
8 | * @link https://nystudio107.com/ |
||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
9 | * @copyright Copyright (c) nystudio107 |
||
0 ignored issues
–
show
|
|||
10 | */ |
||
0 ignored issues
–
show
|
|||
11 | |||
12 | namespace nystudio107\templatecomments\web\twig\nodes; |
||
13 | |||
14 | use Twig\Compiler; |
||
15 | use Twig\Node\Node; |
||
16 | |||
17 | /** |
||
0 ignored issues
–
show
|
|||
18 | * @author nystudio107 |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
|
|||
19 | * @package TemplateComments |
||
0 ignored issues
–
show
|
|||
20 | * @since 1.0.0 |
||
0 ignored issues
–
show
|
|||
21 | */ |
||
0 ignored issues
–
show
|
|||
22 | class CommentsNode extends Node |
||
23 | { |
||
24 | // Public Methods |
||
25 | // ========================================================================= |
||
26 | |||
27 | /** |
||
0 ignored issues
–
show
|
|||
28 | * @inheritdoc |
||
29 | */ |
||
0 ignored issues
–
show
|
|||
30 | public function compile(Compiler $compiler): void |
||
31 | { |
||
32 | $compiler |
||
33 | ->addDebugInfo($this) |
||
34 | ->write('$_templateTimer = microtime(true)') |
||
35 | ->raw(";\n") |
||
36 | ->write('$_templateName = ') |
||
37 | ->subcompile($this->getNode('templateName')) |
||
38 | ->raw(";\n") |
||
39 | ->write('echo PHP_EOL."<!-- >>> TEMPLATE BEGIN >>> ".$_templateName." -->".PHP_EOL') |
||
40 | ->raw(";\n"); |
||
41 | // Make sure there is a body node |
||
42 | if (!empty($this->nodes['body'])) { |
||
43 | $compiler |
||
44 | ->indent() |
||
45 | ->subcompile($this->getNode('body')) |
||
46 | ->outdent(); |
||
47 | } |
||
48 | $compiler |
||
49 | ->write('echo PHP_EOL."<!-- <<< TEMPLATE END <<< FROM ".$_templateName." TIME ".number_format((microtime(true)-$_templateTimer)*1000,2)."ms -->".PHP_EOL') |
||
50 | ->raw(";\n") |
||
51 | ->write("unset(\$_templateName);\n") |
||
52 | ->write("unset(\$_templateTimer);\n"); |
||
53 | } |
||
54 | } |
||
55 |