Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\HttpKernel\DependencyInjection; Chris@0: Chris@0: use Symfony\Component\DependencyInjection\ContainerInterface; Chris@0: use Symfony\Component\HttpFoundation\RequestStack; Chris@0: use Symfony\Component\HttpKernel\Fragment\FragmentHandler; Chris@0: Chris@0: /** Chris@0: * Lazily loads fragment renderers from the dependency injection container. Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class LazyLoadingFragmentHandler extends FragmentHandler Chris@0: { Chris@0: private $container; Chris@0: private $rendererIds = array(); Chris@0: Chris@0: /** Chris@0: * Constructor. Chris@0: * Chris@0: * @param ContainerInterface $container A container Chris@0: * @param RequestStack $requestStack The Request stack that controls the lifecycle of requests Chris@0: * @param bool $debug Whether the debug mode is enabled or not Chris@0: */ Chris@0: public function __construct(ContainerInterface $container, RequestStack $requestStack, $debug = false) Chris@0: { Chris@0: $this->container = $container; Chris@0: Chris@0: parent::__construct($requestStack, array(), $debug); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a service as a fragment renderer. Chris@0: * Chris@0: * @param string $name The service name Chris@0: * @param string $renderer The render service id Chris@0: */ Chris@0: public function addRendererService($name, $renderer) Chris@0: { Chris@0: $this->rendererIds[$name] = $renderer; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function render($uri, $renderer = 'inline', array $options = array()) Chris@0: { Chris@0: if (isset($this->rendererIds[$renderer])) { Chris@0: $this->addRenderer($this->container->get($this->rendererIds[$renderer])); Chris@0: Chris@0: unset($this->rendererIds[$renderer]); Chris@0: } Chris@0: Chris@0: return parent::render($uri, $renderer, $options); Chris@0: } Chris@0: }