Completed
Pull Request — master (#6)
by Benjamin
12:56
created

DisplayLinkExtension::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Alpixel\Bundle\MenuBundle\Twig;
4
5
class DisplayLinkExtension extends \Twig_Extension
6
{
7
    public function getFunctions()
8
    {
9
        return [
10
            new \Twig_SimpleFunction('alpixel_menu_link', [$this, 'menuLink'], ['needs_environment' => true]),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
11
        ];
12
    }
13
14
    /**
15
     * Add app_dev.php in dev environment if the link is locale.
16
     *
17
     * @param \Twig_Environment $twig
18
     * @param $link
19
     *
20
     * @return string
21
     */
22
    public function menuLink(\Twig_Environment $twig, $link)
23
    {
24
        $globals = $twig->getGlobals();
25
        $app = $globals['app'];
26
        $env = $app->getEnvironment();
27
28
        if ($env === 'dev' && strpos($link, 'http') === false) {
29
            $dev = ($link[0] === '/') ? 'app_dev.php' : 'app_dev.php/';
30
            $link = $dev.$link;
31
        }
32
33
        return $link;
34
    }
35
36
    public function getName()
37
    {
38
        return 'alpixel_menu_menu_link';
39
    }
40
}
41