Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

DebugTemplate.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishDebugBundle\Twig;
8
9 use Symfony\Component\Filesystem\Filesystem;
10 use Twig_Template;
11
18 class DebugTemplate extends Twig_Template
19 {
20 private $fileSystem;
21
22 public function display(array $context, array $blocks = [])
23 {
24 $this->fileSystem = $this->fileSystem ?: new Filesystem();
25
26 // Bufferize to be able to insert template name as HTML comments if applicable.
27 // Layout template name will only appear at the end, to avoid potential quirks with old browsers
28 // when comments appear before doctype declaration.
29 ob_start();
30 parent::display($context, $blocks);
31 $templateResult = ob_get_clean();
32
33 $templateName = trim($this->fileSystem->makePathRelative($this->getSourceContext()->getPath(), dirname(getcwd())), '/');
34 // Check if template name ends with "html.twig", indicating this is an HTML template.
35 $isHtmlTemplate = substr($templateName, -strlen('html.twig')) === 'html.twig';
36 $templateName = $isHtmlTemplate ? $templateName . ' (' . $this->getSourceContext()->getName() . ')' : $templateName;
37
38 // Display start template comment, if applicable.
39 if ($isHtmlTemplate) {
40 if (stripos(trim($templateResult), '<!doctype') !== false) {
41 $templateResult = preg_replace(
42 '#(<!doctype[^>]+>)#im',
43 "$1\n<!-- START " . $templateName . ' -->',
44 $templateResult
45 );
46 } else {
47 echo "\n<!-- START $templateName -->\n";
48 }
49 }
50
51 // Display stop template comment after result, if applicable.
52 if ($isHtmlTemplate) {
53 $bodyPos = stripos($templateResult, '</body>');
54 if ($bodyPos !== false) {
55 // Add layout template name before </body>, to avoid display quirks in some browsers.
56 echo substr($templateResult, 0, $bodyPos)
57 . "\n<!-- STOP $templateName -->\n"
58 . substr($templateResult, $bodyPos);
59 } else {
60 echo $templateResult;
61 echo "\n<!-- STOP $templateName -->\n";
62 }
63 } else {
64 echo $templateResult;
65 }
66 }
67
71 public function getTemplateName()
72 {
73 return '';
74 }
75
79 public function getSource()
80 {
81 return '';
82 }
83
87 protected function doDisplay(array $context, array $blocks = [])
88 {
89 return '';
90 }
91
95 public function getDebugInfo()
96 {
97 return [];
98 }
99 }
eZ\Bundle\EzPublishDebugBundle\Twig\DebugTemplate
Meant to be used as a Twig base template class.
Definition: DebugTemplate.php:19
eZ\Bundle\EzPublishDebugBundle\Twig\DebugTemplate\$fileSystem
$fileSystem
Definition: DebugTemplate.php:20
eZ\Bundle\EzPublishDebugBundle\Twig\DebugTemplate\getSource
getSource()
{}
Definition: DebugTemplate.php:79
eZ\Bundle\EzPublishDebugBundle\Twig\DebugTemplate\doDisplay
doDisplay(array $context, array $blocks=[])
{}
Definition: DebugTemplate.php:87
eZ\Bundle\EzPublishDebugBundle\Twig\DebugTemplate\display
display(array $context, array $blocks=[])
Definition: DebugTemplate.php:22
eZ\Bundle\EzPublishDebugBundle\Twig\DebugTemplate\getTemplateName
getTemplateName()
{}
Definition: DebugTemplate.php:71
eZ\Bundle\EzPublishDebugBundle\Twig\DebugTemplate\getDebugInfo
getDebugInfo()
{}
Definition: DebugTemplate.php:95
eZ\Bundle\EzPublishDebugBundle\Twig
Definition: DebugTemplate.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.