4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Bridge\Twig\Extension
;
14 use Symfony\Component\HttpKernel\Fragment\FragmentHandler
;
15 use Symfony\Component\HttpKernel\Controller\ControllerReference
;
18 * Provides integration with the HttpKernel component.
20 * @author Fabien Potencier <fabien@symfony.com>
22 class HttpKernelExtension
extends \Twig_Extension
29 * @param FragmentHandler $handler A FragmentHandler instance
31 public function __construct(FragmentHandler
$handler)
33 $this->handler
= $handler;
36 public function getFunctions()
39 'render' => new \
Twig_Function_Method($this, 'renderFragment', array('is_safe' => array('html'))),
40 'render_*' => new \
Twig_Function_Method($this, 'renderFragmentStrategy', array('is_safe' => array('html'))),
41 'controller' => new \
Twig_Function_Method($this, 'controller'),
48 * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
49 * @param array $options An array of options
51 * @return string The fragment content
53 * @see Symfony\Component\HttpKernel\Fragment\FragmentHandler::render()
55 public function renderFragment($uri, $options = array())
57 $strategy = isset($options['strategy']) ? $options['strategy'] : 'inline';
58 unset($options['strategy']);
60 return $this->handler
->render($uri, $strategy, $options);
66 * @param string $strategy A strategy name
67 * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
68 * @param array $options An array of options
70 * @return string The fragment content
72 * @see Symfony\Component\HttpKernel\Fragment\FragmentHandler::render()
74 public function renderFragmentStrategy($strategy, $uri, $options = array())
76 return $this->handler
->render($uri, $strategy, $options);
79 public function controller($controller, $attributes = array(), $query = array())
81 return new ControllerReference($controller, $attributes, $query);
84 public function getName()