Completed
Push — master ( 06c1ce...67d37c )
by Jeroen
06:20
created

Twig/MultiDomainTwigExtension.php (1 issue)

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
use Twig\Extension\AbstractExtension;
7
use Twig\TwigFunction;
8
9
/**
10
 * @final since 5.4
11
 */
12
class MultiDomainTwigExtension extends AbstractExtension
13
{
14
    /**
15
     * @var DomainConfigurationInterface
16
     */
17
    private $domainConfiguration;
18
19
    public function __construct(DomainConfigurationInterface $domainConfiguration)
20
    {
21
        $this->domainConfiguration = $domainConfiguration;
22
    }
23
24
    /**
25
     * Get Twig functions defined in this extension.
26
     *
27
     * @return array
28
     */
29
    public function getFunctions()
30
    {
31
        return array(
32
            new TwigFunction('get_multi_domain_hosts', array($this, 'getMultiDomainHosts')),
33
            new TwigFunction('get_current_host', array($this, 'getCurrentHost')),
34
            new TwigFunction('get_extra_data', array($this, 'getExtraData')),
35
            new TwigFunction('get_current_full_host', array($this, 'getCurrentFullHost')),
36
        );
37
    }
38
39
    /**
40
     * @param $key
41
     */
42
    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...
43
    {
44
        $extraData = $this->domainConfiguration->getExtraData();
45
46
        if ($extraData[$key]) {
47
            return $extraData[$key];
48
        }
49
50
        return null;
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public function getMultiDomainHosts()
57
    {
58
        return $this->domainConfiguration->getHosts();
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getCurrentHost()
65
    {
66
        return $this->domainConfiguration->getHost();
67
    }
68
69
    /**
70
     * @return array
71
     */
72
    public function getCurrentFullHost()
73
    {
74
        return $this->domainConfiguration->getFullHost();
75
    }
76
}
77