|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace eZ\Publish\Core\LocationReference; |
|
6
|
|
|
|
|
7
|
|
|
use eZ\Publish\Core\LocationReference\ExpressionLanguage\ExpressionLanguage; |
|
8
|
|
|
use eZ\Publish\Core\LocationReference\NamedReferences\NamedReferencesProviderInterface; |
|
9
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
|
10
|
|
|
|
|
11
|
|
|
final class LocationReferenceResolver implements LocationReferenceResolverInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var \eZ\Publish\Core\LocationReference\LimitedLocationService */ |
|
14
|
|
|
private $limitedLocationService; |
|
15
|
|
|
|
|
16
|
|
|
/** @var \eZ\Publish\Core\LocationReference\NamedReferences\NamedReferencesProviderInterface */ |
|
17
|
|
|
private $namedReferencesProvider; |
|
18
|
|
|
|
|
19
|
|
|
/** @var \Symfony\Component\ExpressionLanguage\ExpressionLanguage */ |
|
20
|
|
|
private $expressionLanguage; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct( |
|
23
|
|
|
LimitedLocationService $limitedLocationService, |
|
24
|
|
|
NamedReferencesProviderInterface $namedReferencesProvider, |
|
25
|
|
|
ExpressionLanguage $expressionLanguage) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->limitedLocationService = $limitedLocationService; |
|
28
|
|
|
$this->namedReferencesProvider = $namedReferencesProvider; |
|
29
|
|
|
$this->expressionLanguage = $expressionLanguage; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function resolve(string $reference): Location |
|
33
|
|
|
{ |
|
34
|
|
|
if ($this->isLocationId($reference)) { |
|
35
|
|
|
return $this->limitedLocationService->loadLocation((int)$reference); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
return $this->expressionLanguage->evaluate($reference, [ |
|
39
|
|
|
'__location_service' => $this->limitedLocationService, |
|
40
|
|
|
'__named_references' => $this->namedReferencesProvider->getNamedReferences(), |
|
41
|
|
|
'__self' => $this, |
|
42
|
|
|
]); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
private function isLocationId(string $reference): bool |
|
46
|
|
|
{ |
|
47
|
|
|
return ctype_digit($reference); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|