4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\DependencyInjection;
14 use Psr\Container\ContainerInterface;
15 use Symfony\Component\HttpFoundation\RequestStack;
16 use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
19 * Lazily loads fragment renderers from the dependency injection container.
21 * @author Fabien Potencier <fabien@symfony.com>
23 class LazyLoadingFragmentHandler extends FragmentHandler
27 * @deprecated since version 3.3, to be removed in 4.0
29 private $rendererIds = array();
30 private $initialized = array();
33 * @param ContainerInterface $container A container
34 * @param RequestStack $requestStack The Request stack that controls the lifecycle of requests
35 * @param bool $debug Whether the debug mode is enabled or not
37 public function __construct(ContainerInterface $container, RequestStack $requestStack, $debug = false)
39 $this->container = $container;
41 parent::__construct($requestStack, array(), $debug);
45 * Adds a service as a fragment renderer.
47 * @param string $name The service name
48 * @param string $renderer The render service id
50 * @deprecated since version 3.3, to be removed in 4.0
52 public function addRendererService($name, $renderer)
54 @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
56 $this->rendererIds[$name] = $renderer;
62 public function render($uri, $renderer = 'inline', array $options = array())
64 // BC 3.x, to be removed in 4.0
65 if (isset($this->rendererIds[$renderer])) {
66 $this->addRenderer($this->container->get($this->rendererIds[$renderer]));
67 unset($this->rendererIds[$renderer]);
69 return parent::render($uri, $renderer, $options);
72 if (!isset($this->initialized[$renderer]) && $this->container->has($renderer)) {
73 $this->addRenderer($this->container->get($renderer));
74 $this->initialized[$renderer] = true;
77 return parent::render($uri, $renderer, $options);