vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Templating/DelegatingEngine.php line 55

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\FrameworkBundle\Templating;
  11. @trigger_error('The '.DelegatingEngine::class.' class is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.', \E_USER_DEPRECATED);
  12. use Psr\Container\ContainerInterface;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Templating\DelegatingEngine as BaseDelegatingEngine;
  15. /**
  16.  * DelegatingEngine selects an engine for a given template.
  17.  *
  18.  * @author Fabien Potencier <fabien@symfony.com>
  19.  *
  20.  * @deprecated since version 4.3, to be removed in 5.0; use Twig instead.
  21.  */
  22. class DelegatingEngine extends BaseDelegatingEngine implements EngineInterface
  23. {
  24.     protected $container;
  25.     public function __construct(ContainerInterface $container, array $engineIds)
  26.     {
  27.         $this->container $container;
  28.         $this->engines $engineIds;
  29.     }
  30.     /**
  31.      * {@inheritdoc}
  32.      */
  33.     public function getEngine($name)
  34.     {
  35.         $this->resolveEngines();
  36.         return parent::getEngine($name);
  37.     }
  38.     /**
  39.      * {@inheritdoc}
  40.      */
  41.     public function renderResponse($view, array $parameters = [], Response $response null)
  42.     {
  43.         $engine $this->getEngine($view);
  44.         if ($engine instanceof EngineInterface) {
  45.             return $engine->renderResponse($view$parameters$response);
  46.         }
  47.         if (null === $response) {
  48.             $response = new Response();
  49.         }
  50.         $response->setContent($engine->render($view$parameters));
  51.         return $response;
  52.     }
  53.     /**
  54.      * Resolved engine ids to their real engine instances from the container.
  55.      */
  56.     private function resolveEngines()
  57.     {
  58.         foreach ($this->engines as $i => $engine) {
  59.             if (\is_string($engine)) {
  60.                 $this->engines[$i] = $this->container->get($engine);
  61.             }
  62.         }
  63.     }
  64. }