Completed
Push — master ( 97e40f...89ec5c )
by André
40:26 queued 12:35
created

ExposedRoutesExtractor::getHost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
namespace eZ\Bundle\EzPublishCoreBundle\Routing\JsRouting;
7
8
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
9
use FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractorInterface;
10
use Symfony\Component\HttpFoundation\Request;
11
12
/**
13
 * Decorator of FOSJsRouting routes extractor.
14
 * Ensures that base URL contains the SiteAccess part when applicable.
15
 */
16
class ExposedRoutesExtractor implements ExposedRoutesExtractorInterface
17
{
18
    /**
19
     * @var ExposedRoutesExtractorInterface
20
     */
21
    private $innerExtractor;
22
23
    /**
24
     * @var Request
25
     */
26
    private $masterRequest;
27
28
    public function __construct(ExposedRoutesExtractorInterface $innerExtractor, Request $masterRequest)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $masterRequest. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
29
    {
30
        $this->innerExtractor = $innerExtractor;
31
        $this->masterRequest = $masterRequest;
32
    }
33
34
    public function getRoutes()
35
    {
36
        return $this->innerExtractor->getRoutes();
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     *
42
     * Will add the SiteAccess if configured in the URI.
43
     *
44
     * @return string
45
     */
46
    public function getBaseUrl()
47
    {
48
        $baseUrl = $this->innerExtractor->getBaseUrl();
49
        $siteAccess = $this->masterRequest->attributes->get('siteaccess');
50
        if ($siteAccess instanceof SiteAccess && $siteAccess->matcher instanceof SiteAccess\URILexer) {
51
            $baseUrl .= $siteAccess->matcher->analyseLink('');
52
        }
53
54
        return $baseUrl;
55
    }
56
57
    public function getPrefix($locale)
58
    {
59
        return $this->innerExtractor->getPrefix($locale);
60
    }
61
62
    public function getHost()
63
    {
64
        return $this->innerExtractor->getHost();
65
    }
66
67
    public function getScheme()
68
    {
69
        return $this->innerExtractor->getScheme();
70
    }
71
72
    public function getCachePath($locale)
73
    {
74
        return $this->innerExtractor->getCachePath($locale);
75
    }
76
77
    public function getResources()
78
    {
79
        return $this->innerExtractor->getResources();
80
    }
81
82
    public function getExposedRoutes()
83
    {
84
        return $this->innerExtractor->getExposedRoutes();
85
    }
86
}
87