vendor/wearemarketing/corebundle/Util/Traits/RendererTrait.php line 22

Open in your IDE?
  1. <?php
  2. namespace WAM\Bundle\CoreBundle\Util\Traits;
  3. use Twig\Environment;
  4. use WAM\Bundle\CoreBundle\Util\Interfaces\RendererAwareInterface;
  5. /**
  6.  * @author Gerard Rico <grico@wearemarketing.com>
  7.  */
  8. trait RendererTrait
  9. {
  10.     protected ?Environment $twig null;
  11.     public function render(string $template, array $context = []): string
  12.     {
  13.         if (is_null($this->twig)) {
  14.             throw new \LogicException('Twig is not initialized yet. Did you forget to add '.
  15.                 RendererAwareInterface::class.' with autoconfigure or a setTwig method call?');
  16.         }
  17.         return $this->twig->render($template$context);
  18.     }
  19.     public function setTwig(Environment $twig): void
  20.     {
  21.         $this->twig $twig;
  22.     }
  23. }