1: <?php
2:
3: 4: 5: 6: 7: 8: 9:
10:
11: namespace Minion\Twig;
12:
13: use Minion\Application;
14: use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
15:
16: 17: 18: 19: 20: 21:
22: class UrlExtension extends \Twig_Extension
23: {
24:
25: private $container;
26:
27: 28: 29: 30: 31: 32: 33:
34: public function __construct(Application $app) {
35: $this->container = $app;
36: }
37:
38: 39: 40:
41: public function getName() {
42: return 'minion_twig_url';
43: }
44:
45: 46: 47:
48: public function getFunctions() {
49: return [
50: new \Twig_Function('url', [$this, 'urlFunction']),
51: new \Twig_Function('path', [$this, 'pathFunction']),
52: ];
53: }
54:
55: 56: 57: 58: 59: 60: 61: 62:
63: public function urlFunction($route, array $params = []) {
64: return $this->container['url_generator']->generate($route, $params, UrlGeneratorInterface::ABSOLUTE_URL);
65: }
66:
67: 68: 69: 70: 71: 72: 73: 74:
75: public function pathFunction($route, array $params = []) {
76: return $this->container['url_generator']->generate($route, $params, UrlGeneratorInterface::ABSOLUTE_PATH);
77: }
78: }