vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/MVC/Symfony/View/Renderer/TemplateRenderer.php line 57

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. namespace eZ\Publish\Core\MVC\Symfony\View\Renderer;
  7. use eZ\Publish\Core\MVC\Exception\NoViewTemplateException;
  8. use eZ\Publish\Core\MVC\Symfony\View\Renderer;
  9. use eZ\Publish\Core\MVC\Symfony\View\View;
  10. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  11. use eZ\Publish\Core\MVC\Symfony\MVCEvents;
  12. use eZ\Publish\Core\MVC\Symfony\Event\PreContentViewEvent;
  13. use Symfony\Component\Templating\EngineInterface as TemplateEngine;
  14. use Closure;
  15. class TemplateRenderer implements Renderer
  16. {
  17.     /** @var \Symfony\Component\Templating\EngineInterface */
  18.     protected $templateEngine;
  19.     /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */
  20.     protected $eventDispatcher;
  21.     public function __construct(TemplateEngine $templateEngineEventDispatcherInterface $eventDispatcher)
  22.     {
  23.         $this->templateEngine $templateEngine;
  24.         $this->eventDispatcher $eventDispatcher;
  25.     }
  26.     /**
  27.      * @param \eZ\Publish\Core\MVC\Symfony\View\View $view
  28.      *
  29.      * @throws NoViewTemplateException
  30.      *
  31.      * @return string
  32.      */
  33.     public function render(View $view)
  34.     {
  35.         $this->eventDispatcher->dispatch(
  36.             MVCEvents::PRE_CONTENT_VIEW,
  37.             new PreContentViewEvent($view)
  38.         );
  39.         $templateIdentifier $view->getTemplateIdentifier();
  40.         if ($templateIdentifier instanceof Closure) {
  41.             return $templateIdentifier($view->getParameters());
  42.         }
  43.         if ($view->getTemplateIdentifier() === null) {
  44.             throw new NoViewTemplateException($view);
  45.         }
  46.         return $this->templateEngine->render(
  47.             $view->getTemplateIdentifier(),
  48.             $view->getParameters()
  49.         );
  50.     }
  51. }