12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?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\Bundle\FrameworkBundle\Templating;
- use Symfony\Component\Templating\DelegatingEngine as BaseDelegatingEngine;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
- use Symfony\Component\HttpFoundation\Response;
- /**
- * DelegatingEngine selects an engine for a given template.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
- class DelegatingEngine extends BaseDelegatingEngine implements EngineInterface
- {
- protected $container;
- /**
- * Constructor.
- *
- * @param ContainerInterface $container The DI container
- */
- public function __construct(ContainerInterface $container, array $engineIds)
- {
- $this->container = $container;
- $this->engines = $engineIds;
- }
- /**
- * {@inheritdoc}
- */
- public function supports($name)
- {
- foreach ($this->engines as $i => $engine) {
- if (is_string($engine)) {
- $engine = $this->engines[$i] = $this->container->get($engine);
- }
- if ($engine->supports($name)) {
- return true;
- }
- }
- return false;
- }
- /**
- * {@inheritdoc}
- */
- protected function getEngine($name)
- {
- foreach ($this->engines as $i => $engine) {
- if (is_string($engine)) {
- $engine = $this->engines[$i] = $this->container->get($engine);
- }
- if ($engine->supports($name)) {
- return $engine;
- }
- }
- throw new \RuntimeException(sprintf('No engine is able to work with the template "%s".', $name));
- }
- /**
- * Renders a view and returns a Response.
- *
- * @param string $view The view name
- * @param array $parameters An array of parameters to pass to the view
- * @param Response $response A Response instance
- *
- * @return Response A Response instance
- */
- public function renderResponse($view, array $parameters = array(), Response $response = null)
- {
- if (null === $response) {
- $response = new Response();
- }
- $response->setContent($this->render($view, $parameters));
- return $response;
- }
- }
|