|
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
|
|
|
use Symfony\Component\Routing\Route; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Decorator of FOSJsRouting routes extractor. |
|
15
|
|
|
* Ensures that base URL contains the SiteAccess part when applicable. |
|
16
|
|
|
*/ |
|
17
|
|
|
class ExposedRoutesExtractor implements ExposedRoutesExtractorInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var ExposedRoutesExtractorInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
private $innerExtractor; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var Request |
|
26
|
|
|
*/ |
|
27
|
|
|
private $masterRequest; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct(ExposedRoutesExtractorInterface $innerExtractor, Request $masterRequest) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$this->innerExtractor = $innerExtractor; |
|
32
|
|
|
$this->masterRequest = $masterRequest; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function getRoutes() |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->innerExtractor->getRoutes(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
* |
|
43
|
|
|
* Will add the SiteAccess if configured in the URI. |
|
44
|
|
|
* |
|
45
|
|
|
* @return string |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getBaseUrl() |
|
48
|
|
|
{ |
|
49
|
|
|
$baseUrl = $this->innerExtractor->getBaseUrl(); |
|
50
|
|
|
$siteAccess = $this->masterRequest->attributes->get('siteaccess'); |
|
51
|
|
|
if ($siteAccess instanceof SiteAccess && $siteAccess->matcher instanceof SiteAccess\URILexer) { |
|
52
|
|
|
$baseUrl .= $siteAccess->matcher->analyseLink(''); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $baseUrl; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getPrefix($locale) |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->innerExtractor->getPrefix($locale); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function getHost() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->innerExtractor->getHost(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getScheme() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->innerExtractor->getScheme(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function getCachePath($locale) |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->innerExtractor->getCachePath($locale); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function getResources() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->innerExtractor->getResources(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function getExposedRoutes() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->innerExtractor->getExposedRoutes(); |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getPort() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->innerExtractor->getPort(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function isRouteExposed(Route $route, $name) |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->innerExtractor->isRouteExposed($route, $name); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|