vendor/sylius/sylius/src/Sylius/Bundle/UiBundle/Twig/TemplateEventExtension.php line 42

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\Twig;
  12. use Sylius\Bundle\UiBundle\Renderer\TemplateEventRendererInterface;
  13. use Twig\Extension\AbstractExtension;
  14. use Twig\TwigFunction;
  15. /**
  16.  * @experimental
  17.  */
  18. final class TemplateEventExtension extends AbstractExtension
  19. {
  20.     private TemplateEventRendererInterface $templateEventRenderer;
  21.     public function __construct(TemplateEventRendererInterface $templateEventRenderer)
  22.     {
  23.         $this->templateEventRenderer $templateEventRenderer;
  24.     }
  25.     public function getFunctions(): array
  26.     {
  27.         return [
  28.             new TwigFunction('sylius_template_event', [$this'render'], ['is_safe' => ['html']]),
  29.         ];
  30.     }
  31.     /**
  32.      * @param string|string[] $eventName
  33.      */
  34.     public function render($eventName, array $context = []): string
  35.     {
  36.         return $this->templateEventRenderer->render((array) $eventName$context);
  37.     }
  38. }