Heimdall/vendor/symfony/http-kernel/DependencyInjection/LazyLoadingFragmentHandler.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2018-02-01 20:01:12 +00:00
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpKernel\DependencyInjection;
use Psr\Container\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
/**
* Lazily loads fragment renderers from the dependency injection container.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class LazyLoadingFragmentHandler extends FragmentHandler
{
private $container;
2022-03-10 11:54:29 +00:00
/**
* @var array<string, bool>
*/
2019-06-11 11:29:32 +00:00
private $initialized = [];
2018-02-01 20:01:12 +00:00
public function __construct(ContainerInterface $container, RequestStack $requestStack, bool $debug = false)
2018-02-01 20:01:12 +00:00
{
$this->container = $container;
2019-06-11 11:29:32 +00:00
parent::__construct($requestStack, [], $debug);
2018-02-01 20:01:12 +00:00
}
/**
* {@inheritdoc}
*/
2022-03-10 11:54:29 +00:00
public function render($uri, string $renderer = 'inline', array $options = [])
2018-02-01 20:01:12 +00:00
{
if (!isset($this->initialized[$renderer]) && $this->container->has($renderer)) {
$this->addRenderer($this->container->get($renderer));
$this->initialized[$renderer] = true;
}
return parent::render($uri, $renderer, $options);
}
}