Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / http-kernel / DependencyInjection / LazyLoadingFragmentHandler.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpKernel\DependencyInjection;
13
14 use Symfony\Component\DependencyInjection\ContainerInterface;
15 use Symfony\Component\HttpFoundation\RequestStack;
16 use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
17
18 /**
19  * Lazily loads fragment renderers from the dependency injection container.
20  *
21  * @author Fabien Potencier <fabien@symfony.com>
22  */
23 class LazyLoadingFragmentHandler extends FragmentHandler
24 {
25     private $container;
26     private $rendererIds = array();
27
28     /**
29      * Constructor.
30      *
31      * @param ContainerInterface $container    A container
32      * @param RequestStack       $requestStack The Request stack that controls the lifecycle of requests
33      * @param bool               $debug        Whether the debug mode is enabled or not
34      */
35     public function __construct(ContainerInterface $container, RequestStack $requestStack, $debug = false)
36     {
37         $this->container = $container;
38
39         parent::__construct($requestStack, array(), $debug);
40     }
41
42     /**
43      * Adds a service as a fragment renderer.
44      *
45      * @param string $name     The service name
46      * @param string $renderer The render service id
47      */
48     public function addRendererService($name, $renderer)
49     {
50         $this->rendererIds[$name] = $renderer;
51     }
52
53     /**
54      * {@inheritdoc}
55      */
56     public function render($uri, $renderer = 'inline', array $options = array())
57     {
58         if (isset($this->rendererIds[$renderer])) {
59             $this->addRenderer($this->container->get($this->rendererIds[$renderer]));
60
61             unset($this->rendererIds[$renderer]);
62         }
63
64         return parent::render($uri, $renderer, $options);
65     }
66 }