1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aoe\Restler\System\TYPO3; |
4
|
|
|
|
5
|
|
|
use Aoe\Restler\System\Restler\Builder as RestlerBuilder; |
6
|
|
|
use TYPO3\CMS\Core\Routing\Aspect\AspectInterface; |
7
|
|
|
use TYPO3\CMS\Core\Routing\Enhancer\DecoratingEnhancerInterface; |
8
|
|
|
use TYPO3\CMS\Core\Routing\RouteCollection; |
9
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
10
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
11
|
|
|
|
12
|
|
|
class RestlerEnhancer implements DecoratingEnhancerInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var RestlerBuilder |
16
|
|
|
*/ |
17
|
|
|
private $restlerBuilder; |
18
|
|
|
|
19
|
|
|
public function __construct($configuration) |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
22
|
|
|
$this->restlerBuilder = $objectManager->get(RestlerBuilder::class); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Gets pattern that can be used to redecorate (undecorate) |
28
|
|
|
* a potential previously decorated route path. |
29
|
|
|
* |
30
|
|
|
* Example: |
31
|
|
|
* + route path: 'first/second.html' |
32
|
|
|
* + redecoration pattern: '(?:\.html|\.json)$' |
33
|
|
|
* -> 'first/second' might be the redecorated route path after |
34
|
|
|
* applying the redecoration pattern to preg_match/preg_replace |
35
|
|
|
* |
36
|
|
|
* @return string regular expression pattern |
37
|
|
|
*/ |
38
|
|
|
public function getRoutePathRedecorationPattern(): string |
39
|
|
|
{ |
40
|
|
|
return '.$'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Decorates route collection to be processed during URL resolving. |
45
|
|
|
* Executed before invoking routing enhancers. |
46
|
|
|
* |
47
|
|
|
* @param RouteCollection $collection |
48
|
|
|
* @param string $routePath URL path |
49
|
|
|
*/ |
50
|
|
|
public function decorateForMatching(RouteCollection $collection, string $routePath): void |
51
|
|
|
{ |
52
|
|
|
$this->restlerBuilder->build(null); |
53
|
|
|
|
54
|
|
|
// set path according to typo3/sysext/core/Classes/Routing/PageRouter.php:132 |
55
|
|
|
$prefixedUrlPath = '/' . trim($routePath, '/'); |
56
|
|
|
|
57
|
|
|
if ($this->isRestlerUrl($prefixedUrlPath)) { |
58
|
|
|
$defaultRoute = $collection->get('default'); |
59
|
|
|
$defaultRoute->setPath($prefixedUrlPath); |
60
|
|
|
$collection->add('restler', $defaultRoute); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Decorates route collection during URL URL generation. |
66
|
|
|
* Executed before invoking routing enhancers. |
67
|
|
|
* |
68
|
|
|
* @param RouteCollection $collection |
69
|
|
|
* @param array $parameters query parameters |
70
|
|
|
*/ |
71
|
|
|
public function decorateForGeneration(RouteCollection $collection, array $parameters): void |
72
|
|
|
{ |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param AspectInterface[] $aspects |
77
|
|
|
*/ |
78
|
|
|
public function setAspects(array $aspects): void |
79
|
|
|
{ |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return AspectInterface[] |
84
|
|
|
*/ |
85
|
|
|
public function getAspects(): array |
86
|
|
|
{ |
87
|
|
|
return []; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
private function isRestlerUrl($uri): bool |
91
|
|
|
{ |
92
|
|
|
return \Aoe\Restler\System\Restler\Routes::containsUrl($uri); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.