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