|
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\Routing\Generator\UrlGeneratorInterface; |
|
15 |
|
16 /** |
|
17 * Provides integration of the Routing component with Twig. |
|
18 * |
|
19 * @author Fabien Potencier <fabien@symfony.com> |
|
20 */ |
|
21 class RoutingExtension extends \Twig_Extension |
|
22 { |
|
23 private $generator; |
|
24 |
|
25 public function __construct(UrlGeneratorInterface $generator) |
|
26 { |
|
27 $this->generator = $generator; |
|
28 } |
|
29 |
|
30 /** |
|
31 * Returns a list of functions to add to the existing list. |
|
32 * |
|
33 * @return array An array of functions |
|
34 */ |
|
35 public function getFunctions() |
|
36 { |
|
37 return array( |
|
38 'url' => new \Twig_Function_Method($this, 'getUrl'), |
|
39 'path' => new \Twig_Function_Method($this, 'getPath'), |
|
40 ); |
|
41 } |
|
42 |
|
43 public function getPath($name, $parameters = array()) |
|
44 { |
|
45 return $this->generator->generate($name, $parameters, false); |
|
46 } |
|
47 |
|
48 public function getUrl($name, $parameters = array()) |
|
49 { |
|
50 return $this->generator->generate($name, $parameters, true); |
|
51 } |
|
52 |
|
53 /** |
|
54 * Returns the name of the extension. |
|
55 * |
|
56 * @return string The extension name |
|
57 */ |
|
58 public function getName() |
|
59 { |
|
60 return 'routing'; |
|
61 } |
|
62 } |