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

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.     /** @var TemplateBlockRendererInterface */
  19.     private $templateBlockRenderer;
  20.     public function __construct(TemplateBlockRendererInterface $templateBlockRenderer)
  21.     {
  22.         $this->templateBlockRenderer $templateBlockRenderer;
  23.     }
  24.     public function render(TemplateBlock $templateBlock, array $context = []): string
  25.     {
  26.         $shouldRenderHtmlDebug strrpos($templateBlock->getTemplate(), '.html.twig') !== false;
  27.         $renderedParts = [];
  28.         if ($shouldRenderHtmlDebug) {
  29.             $renderedParts[] = sprintf(
  30.                 '<!-- BEGIN BLOCK | event name: "%s", block name: "%s", template: "%s", priority: %d -->',
  31.                 $templateBlock->getEventName(),
  32.                 $templateBlock->getName(),
  33.                 $templateBlock->getTemplate(),
  34.                 $templateBlock->getPriority()
  35.             );
  36.         }
  37.         $renderedParts[] = $this->templateBlockRenderer->render($templateBlock$context);
  38.         if ($shouldRenderHtmlDebug) {
  39.             $renderedParts[] = sprintf(
  40.                 '<!-- END BLOCK | event name: "%s", block name: "%s" -->',
  41.                 $templateBlock->getEventName(),
  42.                 $templateBlock->getName()
  43.             );
  44.         }
  45.         return implode("\n"$renderedParts);
  46.     }
  47. }