vendor/sylius/sylius/src/Sylius/Bundle/UiBundle/Renderer/HtmlDebugTemplateBlockRenderer.php line 46

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\UiBundle\Renderer;
  12. use Sylius\Bundle\UiBundle\Registry\TemplateBlock;
  13. /**
  14.  * @experimental
  15.  */
  16. final class HtmlDebugTemplateBlockRenderer implements TemplateBlockRendererInterface
  17. {
  18.     private TemplateBlockRendererInterface $templateBlockRenderer;
  19.     public function __construct(TemplateBlockRendererInterface $templateBlockRenderer)
  20.     {
  21.         $this->templateBlockRenderer $templateBlockRenderer;
  22.     }
  23.     public function render(TemplateBlock $templateBlock, array $context = []): string
  24.     {
  25.         $shouldRenderHtmlDebug strrpos($templateBlock->getTemplate(), '.html.twig') !== false;
  26.         $renderedParts = [];
  27.         if ($shouldRenderHtmlDebug) {
  28.             $renderedParts[] = sprintf(
  29.                 '<!-- BEGIN BLOCK | event name: "%s", block name: "%s", template: "%s", priority: %d -->',
  30.                 $templateBlock->getEventName(),
  31.                 $templateBlock->getName(),
  32.                 $templateBlock->getTemplate(),
  33.                 $templateBlock->getPriority()
  34.             );
  35.         }
  36.         $renderedParts[] = $this->templateBlockRenderer->render($templateBlock$context);
  37.         if ($shouldRenderHtmlDebug) {
  38.             $renderedParts[] = sprintf(
  39.                 '<!-- END BLOCK | event name: "%s", block name: "%s" -->',
  40.                 $templateBlock->getEventName(),
  41.                 $templateBlock->getName()
  42.             );
  43.         }
  44.         return implode("\n"$renderedParts);
  45.     }
  46. }