|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace eZ\Publish\Core\LocationReference\ExpressionLanguage; |
|
6
|
|
|
|
|
7
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
|
8
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionFunction; |
|
9
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; |
|
10
|
|
|
|
|
11
|
|
|
final class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface |
|
12
|
|
|
{ |
|
13
|
|
|
public function getFunctions(): array |
|
14
|
|
|
{ |
|
15
|
|
|
return [ |
|
16
|
|
|
new ExpressionFunction( |
|
17
|
|
|
'remote_id', |
|
18
|
|
|
function (string $args): string { |
|
19
|
|
|
return sprintf('$__location_service->loadLocationByRemoteId(%s)', $args); |
|
20
|
|
|
}, |
|
21
|
|
|
function (array $variables, string $remoteId): Location { |
|
22
|
|
|
return $variables['__location_service']->loadLocationByRemoteId($remoteId); |
|
23
|
|
|
} |
|
24
|
|
|
), |
|
25
|
|
|
new ExpressionFunction( |
|
26
|
|
|
'local_id', |
|
27
|
|
|
function (string $args): string { |
|
28
|
|
|
return sprintf('$__location_service->loadLocation(%s)', $args); |
|
29
|
|
|
}, |
|
30
|
|
|
function (array $variables, int $id): Location { |
|
31
|
|
|
return $variables['__location_service']->loadLocation($id); |
|
32
|
|
|
} |
|
33
|
|
|
), |
|
34
|
|
|
new ExpressionFunction( |
|
35
|
|
|
'path', |
|
36
|
|
|
function (string $args): string { |
|
37
|
|
|
return sprintf('$__location_service->loadLocationByPathString(%s)', $args); |
|
38
|
|
|
}, |
|
39
|
|
|
function (array $variables, string $path): Location { |
|
40
|
|
|
return $variables['__location_service']->loadLocationByPathString($path); |
|
41
|
|
|
} |
|
42
|
|
|
), |
|
43
|
|
|
new ExpressionFunction( |
|
44
|
|
|
'parent', |
|
45
|
|
|
function (string $args): string { |
|
46
|
|
|
return sprintf('$__location_service->loadParentLocation(%s)', $args); |
|
47
|
|
|
}, |
|
48
|
|
|
function (array $variables, Location $location): Location { |
|
49
|
|
|
return $variables['__location_service']->loadParentLocation($location); |
|
50
|
|
|
} |
|
51
|
|
|
), |
|
52
|
|
|
new ExpressionFunction( |
|
53
|
|
|
'root', |
|
54
|
|
|
function (string $args): string { |
|
|
|
|
|
|
55
|
|
|
return '$__self->resolve($___named_references->getReference("__root"))'; |
|
56
|
|
|
}, |
|
57
|
|
|
function (array $variables): Location { |
|
58
|
|
|
return $variables['__self']->resolve($variables['__named_references']->getReference('__root')); |
|
59
|
|
|
} |
|
60
|
|
|
), |
|
61
|
|
|
new ExpressionFunction( |
|
62
|
|
|
'named', |
|
63
|
|
|
function (string $args): string { |
|
64
|
|
|
return sprintf('$__self->resolve($___named_references->getReference(%s))', $args); |
|
65
|
|
|
}, |
|
66
|
|
|
function (array $variables, string $name): Location { |
|
67
|
|
|
return $variables['__self']->resolve($variables['__named_references']->getReference($name)); |
|
68
|
|
|
} |
|
69
|
|
|
), |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.