vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Templating/PhpEngine.php line 78

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 '.PhpEngine::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\Loader\LoaderInterface;
  15. use Symfony\Component\Templating\PhpEngine as BasePhpEngine;
  16. use Symfony\Component\Templating\TemplateNameParserInterface;
  17. /**
  18.  * This engine knows how to render Symfony templates.
  19.  *
  20.  * @author Fabien Potencier <fabien@symfony.com>
  21.  *
  22.  * @deprecated since version 4.3, to be removed in 5.0; use Twig instead.
  23.  */
  24. class PhpEngine extends BasePhpEngine implements EngineInterface
  25. {
  26.     protected $container;
  27.     public function __construct(TemplateNameParserInterface $parserContainerInterface $containerLoaderInterface $loaderGlobalVariables $globals null)
  28.     {
  29.         $this->container $container;
  30.         parent::__construct($parser$loader);
  31.         if (null !== $globals) {
  32.             $this->addGlobal('app'$globals);
  33.         }
  34.     }
  35.     /**
  36.      * {@inheritdoc}
  37.      */
  38.     public function get($name)
  39.     {
  40.         if (!isset($this->helpers[$name])) {
  41.             throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.'$name));
  42.         }
  43.         if (\is_string($this->helpers[$name])) {
  44.             $this->helpers[$name] = $this->container->get($this->helpers[$name]);
  45.             $this->helpers[$name]->setCharset($this->charset);
  46.         }
  47.         return $this->helpers[$name];
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function setHelpers(array $helpers)
  53.     {
  54.         $this->helpers $helpers;
  55.     }
  56.     /**
  57.      * {@inheritdoc}
  58.      */
  59.     public function renderResponse($view, array $parameters = [], Response $response null)
  60.     {
  61.         if (null === $response) {
  62.             $response = new Response();
  63.         }
  64.         $response->setContent($this->render($view$parameters));
  65.         return $response;
  66.     }
  67. }