Overview

Namespaces

  • Minion
    • Service
    • Twig

Classes

  • Minion\Application
  • Minion\Console
  • Minion\Controller
  • Minion\Service\ServiceConfig
  • Minion\Service\ServiceProvider
  • Minion\Twig\AssetExtension
  • Minion\Twig\MiscExtension
  • Minion\Twig\TwigExtensionTagServiceProvider
  • Minion\Twig\UrlExtension
  • Minion\Utils

Interfaces

  • Minion\ControllerInterface
  • Minion\Service\ServiceConfigInterface
  • Minion\Service\ServiceProviderInterface
  • Overview
  • Namespace
  • Class
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Minion package.
 5:  * For the full copyright and license information, please view the LICENSE
 6:  * file that was distributed with this source code.
 7:  *
 8:  * @license MIT License
 9:  */
10: 
11: namespace Minion\Twig;
12: 
13: use Minion\Application;
14: use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
15: 
16: /**
17:  * Class UrlExtension.
18:  *
19:  * @package Minion
20:  * @author Damian SzczerbiƄski <dszczer@gmail.com>
21:  */
22: class UrlExtension extends \Twig_Extension
23: {
24:     /** @var Application Application container */
25:     private $container;
26: 
27:     /**
28:      * UrlExtension constructor.
29:      *
30:      * Inject dependencies.
31:      *
32:      * @param Application $app Framework
33:      */
34:     public function __construct(Application $app) {
35:         $this->container = $app;
36:     }
37: 
38:     /**
39:      * {@inheritdoc}
40:      */
41:     public function getName() {
42:         return 'minion_twig_url';
43:     }
44: 
45:     /**
46:      * {@inheritdoc}
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:      * Generate absolute URL path.
57:      *
58:      * @param string $route  Route name
59:      * @param array  $params Parameters
60:      *
61:      * @return string
62:      */
63:     public function urlFunction($route, array $params = []) {
64:         return $this->container['url_generator']->generate($route, $params, UrlGeneratorInterface::ABSOLUTE_URL);
65:     }
66: 
67:     /**
68:      * Generate relative URL path.
69:      *
70:      * @param string $route  Route name
71:      * @param array  $params Parameters
72:      *
73:      * @return string
74:      */
75:     public function pathFunction($route, array $params = []) {
76:         return $this->container['url_generator']->generate($route, $params, UrlGeneratorInterface::ABSOLUTE_PATH);
77:     }
78: }
API documentation generated by ApiGen