Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

Twig/MultiDomainTwigExtension.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\MultiDomainBundle\Twig;
4
5
use Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface;
6
7
class MultiDomainTwigExtension extends \Twig_Extension
8
{
9
    /**
10
     * @var DomainConfigurationInterface
11
     */
12
    private $domainConfiguration;
13
14
    public function __construct(DomainConfigurationInterface $domainConfiguration)
15
    {
16
        $this->domainConfiguration = $domainConfiguration;
17
    }
18
19
    /**
20
     * Get Twig functions defined in this extension.
21
     *
22
     * @return array
23
     */
24
    public function getFunctions()
25
    {
26
        return array(
27
            new \Twig_SimpleFunction('get_multi_domain_hosts', array($this, 'getMultiDomainHosts')),
28
            new \Twig_SimpleFunction('get_current_host', array($this, 'getCurrentHost')),
29
            new \Twig_SimpleFunction('get_extra_data', array($this, 'getExtraData')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

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...
30
            new \Twig_SimpleFunction('get_current_full_host', array($this, 'getCurrentFullHost')),
31
        );
32
    }
33
34
    /**
35
     * @param $key
36
     */
37
    public function getExtraData($key)
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
38
    {
39
        $extraData = $this->domainConfiguration->getExtraData();
40
41
        if ($extraData[$key]) {
42
            return $extraData[$key];
43
        }
44
45
        return null;
46
    }
47
48
    /**
49
     * @return array
50
     */
51
    public function getMultiDomainHosts()
52
    {
53
        return $this->domainConfiguration->getHosts();
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getCurrentHost()
60
    {
61
        return $this->domainConfiguration->getHost();
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    public function getCurrentFullHost()
68
    {
69
        return $this->domainConfiguration->getFullHost();
70
    }
71
}
72