| 148 |
lars |
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\Controller\ControllerReference;
|
|
|
17 |
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Lazily loads fragment renderers from the dependency injection container.
|
|
|
21 |
*
|
|
|
22 |
* @author Fabien Potencier <fabien@symfony.com>
|
|
|
23 |
*/
|
|
|
24 |
class LazyLoadingFragmentHandler extends FragmentHandler
|
|
|
25 |
{
|
|
|
26 |
private ContainerInterface $container;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* @var array<string, bool>
|
|
|
30 |
*/
|
|
|
31 |
private array $initialized = [];
|
|
|
32 |
|
|
|
33 |
public function __construct(ContainerInterface $container, RequestStack $requestStack, bool $debug = false)
|
|
|
34 |
{
|
|
|
35 |
$this->container = $container;
|
|
|
36 |
|
|
|
37 |
parent::__construct($requestStack, [], $debug);
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
public function render(string|ControllerReference $uri, string $renderer = 'inline', array $options = []): ?string
|
|
|
41 |
{
|
|
|
42 |
if (!isset($this->initialized[$renderer]) && $this->container->has($renderer)) {
|
|
|
43 |
$this->addRenderer($this->container->get($renderer));
|
|
|
44 |
$this->initialized[$renderer] = true;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
return parent::render($uri, $renderer, $options);
|
|
|
48 |
}
|
|
|
49 |
}
|