@@ -21,137 +21,137 @@ |
||
21 | 21 | */ |
22 | 22 | class RequestViewHelper extends AbstractViewHelper |
23 | 23 | { |
24 | - /** |
|
25 | - * @Flow\Inject |
|
26 | - * @var Dispatcher |
|
27 | - */ |
|
28 | - protected $dispatcher; |
|
29 | - |
|
30 | - /** |
|
31 | - * @Flow\Inject(lazy=false) |
|
32 | - * @var Bootstrap |
|
33 | - */ |
|
34 | - protected $bootstrap; |
|
35 | - |
|
36 | - /** |
|
37 | - * @Flow\Inject(lazy=false) |
|
38 | - * @var Router |
|
39 | - */ |
|
40 | - protected $router; |
|
41 | - |
|
42 | - /** |
|
43 | - * @Flow\Inject(lazy=false) |
|
44 | - * @var SecurityContext |
|
45 | - */ |
|
46 | - protected $securityContext; |
|
47 | - |
|
48 | - /** |
|
49 | - * @Flow\Inject |
|
50 | - * @var ConfigurationManager |
|
51 | - */ |
|
52 | - protected $configurationManager; |
|
53 | - |
|
54 | - /** |
|
55 | - * @Flow\InjectConfiguration(path="routing.supportEmptySegmentForDimensions", package="Neos.Neos") |
|
56 | - * @var boolean |
|
57 | - */ |
|
58 | - protected $supportEmptySegmentForDimensions; |
|
59 | - |
|
60 | - /** |
|
61 | - * @Flow\Inject |
|
62 | - * @var ContentDimensionPresetSourceInterface |
|
63 | - */ |
|
64 | - protected $contentDimensionPresetSource; |
|
65 | - |
|
66 | - /** |
|
67 | - * Initialize this engine |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public function initializeObject() |
|
72 | - { |
|
73 | - $this->router->setRoutesConfiguration($this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_ROUTES)); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param string $path |
|
78 | - * @return string |
|
79 | - * @throws \Exception |
|
80 | - */ |
|
81 | - public function render($path = null) |
|
82 | - { |
|
83 | - $this->appendFirstUriPartIfValidDimension($path); |
|
84 | - /** @var RequestHandler $activeRequestHandler */ |
|
85 | - $activeRequestHandler = $this->bootstrap->getActiveRequestHandler(); |
|
86 | - $parentHttpRequest = $activeRequestHandler->getHttpRequest(); |
|
87 | - $uri = rtrim($parentHttpRequest->getBaseUri(), '/') . '/' . $path; |
|
88 | - $httpRequest = Request::create(new Uri($uri)); |
|
89 | - $matchingRoute = $this->router->route($httpRequest); |
|
90 | - if (!$matchingRoute) { |
|
91 | - $exception = new \Exception(sprintf('Uri with path "%s" could not be found.', $uri), 1426446160); |
|
92 | - $exceptionHandler = set_exception_handler(null)[0]; |
|
93 | - $exceptionHandler->handleException($exception); |
|
94 | - exit(); |
|
95 | - } |
|
96 | - $request = new ActionRequest($parentHttpRequest); |
|
97 | - foreach ($matchingRoute as $argumentName => $argumentValue) { |
|
98 | - $request->setArgument($argumentName, $argumentValue); |
|
99 | - } |
|
100 | - $response = new Response($activeRequestHandler->getHttpResponse()); |
|
101 | - |
|
102 | - $this->securityContext->withoutAuthorizationChecks(function () use ($request, $response) { |
|
103 | - $this->dispatcher->dispatch($request, $response); |
|
104 | - }); |
|
105 | - |
|
106 | - return $response->getContent(); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @param string $path |
|
111 | - * @return void |
|
112 | - */ |
|
113 | - protected function appendFirstUriPartIfValidDimension(&$path) |
|
114 | - { |
|
115 | - $requestPath = ltrim($this->controllerContext->getRequest()->getHttpRequest()->getUri()->getPath(), '/'); |
|
116 | - $matches = []; |
|
117 | - preg_match(FrontendNodeRoutePartHandler::DIMENSION_REQUEST_PATH_MATCHER, $requestPath, $matches); |
|
118 | - if (!isset($matches['firstUriPart']) && !isset($matches['dimensionPresetUriSegments'])) { |
|
119 | - return; |
|
120 | - } |
|
121 | - |
|
122 | - $dimensionPresets = $this->contentDimensionPresetSource->getAllPresets(); |
|
123 | - if (count($dimensionPresets) === 0) { |
|
124 | - return; |
|
125 | - } |
|
126 | - |
|
127 | - $firstUriPartExploded = explode('_', $matches['firstUriPart'] ?: $matches['dimensionPresetUriSegments']); |
|
128 | - if ($this->supportEmptySegmentForDimensions) { |
|
129 | - foreach ($firstUriPartExploded as $uriSegment) { |
|
130 | - $uriSegmentIsValid = false; |
|
131 | - foreach ($dimensionPresets as $dimensionName => $dimensionPreset) { |
|
132 | - $preset = $this->contentDimensionPresetSource->findPresetByUriSegment($dimensionName, $uriSegment); |
|
133 | - if ($preset !== null) { |
|
134 | - $uriSegmentIsValid = true; |
|
135 | - break; |
|
136 | - } |
|
137 | - } |
|
138 | - if (!$uriSegmentIsValid) { |
|
139 | - return; |
|
140 | - } |
|
141 | - } |
|
142 | - } else { |
|
143 | - if (count($firstUriPartExploded) !== count($dimensionPresets)) { |
|
144 | - return; |
|
145 | - } |
|
146 | - foreach ($dimensionPresets as $dimensionName => $dimensionPreset) { |
|
147 | - $uriSegment = array_shift($firstUriPartExploded); |
|
148 | - $preset = $this->contentDimensionPresetSource->findPresetByUriSegment($dimensionName, $uriSegment); |
|
149 | - if ($preset === null) { |
|
150 | - return; |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - $path = $matches['firstUriPart'] . '/' . $path; |
|
156 | - } |
|
24 | + /** |
|
25 | + * @Flow\Inject |
|
26 | + * @var Dispatcher |
|
27 | + */ |
|
28 | + protected $dispatcher; |
|
29 | + |
|
30 | + /** |
|
31 | + * @Flow\Inject(lazy=false) |
|
32 | + * @var Bootstrap |
|
33 | + */ |
|
34 | + protected $bootstrap; |
|
35 | + |
|
36 | + /** |
|
37 | + * @Flow\Inject(lazy=false) |
|
38 | + * @var Router |
|
39 | + */ |
|
40 | + protected $router; |
|
41 | + |
|
42 | + /** |
|
43 | + * @Flow\Inject(lazy=false) |
|
44 | + * @var SecurityContext |
|
45 | + */ |
|
46 | + protected $securityContext; |
|
47 | + |
|
48 | + /** |
|
49 | + * @Flow\Inject |
|
50 | + * @var ConfigurationManager |
|
51 | + */ |
|
52 | + protected $configurationManager; |
|
53 | + |
|
54 | + /** |
|
55 | + * @Flow\InjectConfiguration(path="routing.supportEmptySegmentForDimensions", package="Neos.Neos") |
|
56 | + * @var boolean |
|
57 | + */ |
|
58 | + protected $supportEmptySegmentForDimensions; |
|
59 | + |
|
60 | + /** |
|
61 | + * @Flow\Inject |
|
62 | + * @var ContentDimensionPresetSourceInterface |
|
63 | + */ |
|
64 | + protected $contentDimensionPresetSource; |
|
65 | + |
|
66 | + /** |
|
67 | + * Initialize this engine |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public function initializeObject() |
|
72 | + { |
|
73 | + $this->router->setRoutesConfiguration($this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_ROUTES)); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param string $path |
|
78 | + * @return string |
|
79 | + * @throws \Exception |
|
80 | + */ |
|
81 | + public function render($path = null) |
|
82 | + { |
|
83 | + $this->appendFirstUriPartIfValidDimension($path); |
|
84 | + /** @var RequestHandler $activeRequestHandler */ |
|
85 | + $activeRequestHandler = $this->bootstrap->getActiveRequestHandler(); |
|
86 | + $parentHttpRequest = $activeRequestHandler->getHttpRequest(); |
|
87 | + $uri = rtrim($parentHttpRequest->getBaseUri(), '/') . '/' . $path; |
|
88 | + $httpRequest = Request::create(new Uri($uri)); |
|
89 | + $matchingRoute = $this->router->route($httpRequest); |
|
90 | + if (!$matchingRoute) { |
|
91 | + $exception = new \Exception(sprintf('Uri with path "%s" could not be found.', $uri), 1426446160); |
|
92 | + $exceptionHandler = set_exception_handler(null)[0]; |
|
93 | + $exceptionHandler->handleException($exception); |
|
94 | + exit(); |
|
95 | + } |
|
96 | + $request = new ActionRequest($parentHttpRequest); |
|
97 | + foreach ($matchingRoute as $argumentName => $argumentValue) { |
|
98 | + $request->setArgument($argumentName, $argumentValue); |
|
99 | + } |
|
100 | + $response = new Response($activeRequestHandler->getHttpResponse()); |
|
101 | + |
|
102 | + $this->securityContext->withoutAuthorizationChecks(function () use ($request, $response) { |
|
103 | + $this->dispatcher->dispatch($request, $response); |
|
104 | + }); |
|
105 | + |
|
106 | + return $response->getContent(); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @param string $path |
|
111 | + * @return void |
|
112 | + */ |
|
113 | + protected function appendFirstUriPartIfValidDimension(&$path) |
|
114 | + { |
|
115 | + $requestPath = ltrim($this->controllerContext->getRequest()->getHttpRequest()->getUri()->getPath(), '/'); |
|
116 | + $matches = []; |
|
117 | + preg_match(FrontendNodeRoutePartHandler::DIMENSION_REQUEST_PATH_MATCHER, $requestPath, $matches); |
|
118 | + if (!isset($matches['firstUriPart']) && !isset($matches['dimensionPresetUriSegments'])) { |
|
119 | + return; |
|
120 | + } |
|
121 | + |
|
122 | + $dimensionPresets = $this->contentDimensionPresetSource->getAllPresets(); |
|
123 | + if (count($dimensionPresets) === 0) { |
|
124 | + return; |
|
125 | + } |
|
126 | + |
|
127 | + $firstUriPartExploded = explode('_', $matches['firstUriPart'] ?: $matches['dimensionPresetUriSegments']); |
|
128 | + if ($this->supportEmptySegmentForDimensions) { |
|
129 | + foreach ($firstUriPartExploded as $uriSegment) { |
|
130 | + $uriSegmentIsValid = false; |
|
131 | + foreach ($dimensionPresets as $dimensionName => $dimensionPreset) { |
|
132 | + $preset = $this->contentDimensionPresetSource->findPresetByUriSegment($dimensionName, $uriSegment); |
|
133 | + if ($preset !== null) { |
|
134 | + $uriSegmentIsValid = true; |
|
135 | + break; |
|
136 | + } |
|
137 | + } |
|
138 | + if (!$uriSegmentIsValid) { |
|
139 | + return; |
|
140 | + } |
|
141 | + } |
|
142 | + } else { |
|
143 | + if (count($firstUriPartExploded) !== count($dimensionPresets)) { |
|
144 | + return; |
|
145 | + } |
|
146 | + foreach ($dimensionPresets as $dimensionName => $dimensionPreset) { |
|
147 | + $uriSegment = array_shift($firstUriPartExploded); |
|
148 | + $preset = $this->contentDimensionPresetSource->findPresetByUriSegment($dimensionName, $uriSegment); |
|
149 | + if ($preset === null) { |
|
150 | + return; |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + $path = $matches['firstUriPart'] . '/' . $path; |
|
156 | + } |
|
157 | 157 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | /** @var RequestHandler $activeRequestHandler */ |
85 | 85 | $activeRequestHandler = $this->bootstrap->getActiveRequestHandler(); |
86 | 86 | $parentHttpRequest = $activeRequestHandler->getHttpRequest(); |
87 | - $uri = rtrim($parentHttpRequest->getBaseUri(), '/') . '/' . $path; |
|
87 | + $uri = rtrim($parentHttpRequest->getBaseUri(), '/').'/'.$path; |
|
88 | 88 | $httpRequest = Request::create(new Uri($uri)); |
89 | 89 | $matchingRoute = $this->router->route($httpRequest); |
90 | 90 | if (!$matchingRoute) { |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | } |
100 | 100 | $response = new Response($activeRequestHandler->getHttpResponse()); |
101 | 101 | |
102 | - $this->securityContext->withoutAuthorizationChecks(function () use ($request, $response) { |
|
102 | + $this->securityContext->withoutAuthorizationChecks(function() use ($request, $response) { |
|
103 | 103 | $this->dispatcher->dispatch($request, $response); |
104 | 104 | }); |
105 | 105 | |
@@ -152,6 +152,6 @@ discard block |
||
152 | 152 | } |
153 | 153 | } |
154 | 154 | |
155 | - $path = $matches['firstUriPart'] . '/' . $path; |
|
155 | + $path = $matches['firstUriPart'].'/'.$path; |
|
156 | 156 | } |
157 | 157 | } |