]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / twig-bridge / Symfony / Bridge / Twig / Extension / HttpKernelExtension.php
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\Bridge\Twig\Extension;
13
14 use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
15 use Symfony\Component\HttpKernel\Controller\ControllerReference;
16
17 /**
18 * Provides integration with the HttpKernel component.
19 *
20 * @author Fabien Potencier <fabien@symfony.com>
21 */
22 class HttpKernelExtension extends \Twig_Extension
23 {
24 private $handler;
25
26 /**
27 * Constructor.
28 *
29 * @param FragmentHandler $handler A FragmentHandler instance
30 */
31 public function __construct(FragmentHandler $handler)
32 {
33 $this->handler = $handler;
34 }
35
36 public function getFunctions()
37 {
38 return array(
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'),
42 );
43 }
44
45 /**
46 * Renders a fragment.
47 *
48 * @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
49 * @param array $options An array of options
50 *
51 * @return string The fragment content
52 *
53 * @see Symfony\Component\HttpKernel\Fragment\FragmentHandler::render()
54 */
55 public function renderFragment($uri, $options = array())
56 {
57 $strategy = isset($options['strategy']) ? $options['strategy'] : 'inline';
58 unset($options['strategy']);
59
60 return $this->handler->render($uri, $strategy, $options);
61 }
62
63 /**
64 * Renders a fragment.
65 *
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
69 *
70 * @return string The fragment content
71 *
72 * @see Symfony\Component\HttpKernel\Fragment\FragmentHandler::render()
73 */
74 public function renderFragmentStrategy($strategy, $uri, $options = array())
75 {
76 return $this->handler->render($uri, $strategy, $options);
77 }
78
79 public function controller($controller, $attributes = array(), $query = array())
80 {
81 return new ControllerReference($controller, $attributes, $query);
82 }
83
84 public function getName()
85 {
86 return 'http_kernel';
87 }
88 }