comparison vendor/symfony/http-kernel/DependencyInjection/LazyLoadingFragmentHandler.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
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 Psr\Container\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 /**
27 * @deprecated since version 3.3, to be removed in 4.0
28 */
29 private $rendererIds = array();
30 private $initialized = array();
31
32 /**
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
36 */
37 public function __construct(ContainerInterface $container, RequestStack $requestStack, $debug = false)
38 {
39 $this->container = $container;
40
41 parent::__construct($requestStack, array(), $debug);
42 }
43
44 /**
45 * Adds a service as a fragment renderer.
46 *
47 * @param string $name The service name
48 * @param string $renderer The render service id
49 *
50 * @deprecated since version 3.3, to be removed in 4.0
51 */
52 public function addRendererService($name, $renderer)
53 {
54 @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
55
56 $this->rendererIds[$name] = $renderer;
57 }
58
59 /**
60 * {@inheritdoc}
61 */
62 public function render($uri, $renderer = 'inline', array $options = array())
63 {
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]);
68
69 return parent::render($uri, $renderer, $options);
70 }
71
72 if (!isset($this->initialized[$renderer]) && $this->container->has($renderer)) {
73 $this->addRenderer($this->container->get($renderer));
74 $this->initialized[$renderer] = true;
75 }
76
77 return parent::render($uri, $renderer, $options);
78 }
79 }