Completed
Pull Request — master (#19)
by
unknown
04:08
created
Classes/ViewHelpers/RequestViewHelper.php 2 patches
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -24,173 +24,173 @@
 block discarded – undo
24 24
  */
25 25
 class RequestViewHelper extends AbstractViewHelper
26 26
 {
27
-    /**
28
-     * @Flow\Inject
29
-     * @var Dispatcher
30
-     */
31
-    protected $dispatcher;
32
-
33
-    /**
34
-     * @Flow\Inject(lazy=false)
35
-     * @var Bootstrap
36
-     */
37
-    protected $bootstrap;
38
-
39
-    /**
40
-     * @Flow\Inject(lazy=false)
41
-     * @var Router
42
-     */
43
-    protected $router;
44
-
45
-    /**
46
-     * @Flow\Inject(lazy=false)
47
-     * @var SecurityContext
48
-     */
49
-    protected $securityContext;
50
-
51
-    /**
52
-     * @Flow\Inject
53
-     * @var ConfigurationManager
54
-     */
55
-    protected $configurationManager;
56
-
57
-    /**
58
-     * @Flow\InjectConfiguration(path="routing.supportEmptySegmentForDimensions", package="Neos.Neos")
59
-     * @var boolean
60
-     */
61
-    protected $supportEmptySegmentForDimensions;
62
-
63
-    /**
64
-     * @Flow\Inject
65
-     * @var ContentDimensionPresetSourceInterface
66
-     */
67
-    protected $contentDimensionPresetSource;
68
-
69
-    /**
70
-     * @Flow\Inject
71
-     * @var ServerRequestFactory
72
-     */
73
-    protected $serverRequestFactory;
74
-
75
-    /**
76
-     * Initialize this engine
77
-     *
78
-     * @return void
79
-     */
80
-    public function initializeObject()
81
-    {
82
-        $this->router->setRoutesConfiguration($this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_ROUTES));
83
-    }
27
+	/**
28
+	 * @Flow\Inject
29
+	 * @var Dispatcher
30
+	 */
31
+	protected $dispatcher;
32
+
33
+	/**
34
+	 * @Flow\Inject(lazy=false)
35
+	 * @var Bootstrap
36
+	 */
37
+	protected $bootstrap;
38
+
39
+	/**
40
+	 * @Flow\Inject(lazy=false)
41
+	 * @var Router
42
+	 */
43
+	protected $router;
44
+
45
+	/**
46
+	 * @Flow\Inject(lazy=false)
47
+	 * @var SecurityContext
48
+	 */
49
+	protected $securityContext;
50
+
51
+	/**
52
+	 * @Flow\Inject
53
+	 * @var ConfigurationManager
54
+	 */
55
+	protected $configurationManager;
56
+
57
+	/**
58
+	 * @Flow\InjectConfiguration(path="routing.supportEmptySegmentForDimensions", package="Neos.Neos")
59
+	 * @var boolean
60
+	 */
61
+	protected $supportEmptySegmentForDimensions;
62
+
63
+	/**
64
+	 * @Flow\Inject
65
+	 * @var ContentDimensionPresetSourceInterface
66
+	 */
67
+	protected $contentDimensionPresetSource;
68
+
69
+	/**
70
+	 * @Flow\Inject
71
+	 * @var ServerRequestFactory
72
+	 */
73
+	protected $serverRequestFactory;
74
+
75
+	/**
76
+	 * Initialize this engine
77
+	 *
78
+	 * @return void
79
+	 */
80
+	public function initializeObject()
81
+	{
82
+		$this->router->setRoutesConfiguration($this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_ROUTES));
83
+	}
84 84
     
85
-    /**
86
-     * @return void
87
-     * @throws \Neos\FluidAdaptor\Core\ViewHelper\Exception
88
-     * @api
89
-     */
90
-    public function initializeArguments()
91
-    {
92
-        parent::initializeArguments();
93
-        $this->registerArgument('path', 'string', 'Path');
94
-    }
95
-
96
-    /**
97
-     * @return string
98
-     * @throws \Exception
99
-     */
100
-    public function render()
101
-    {
102
-        $this->appendFirstUriPartIfValidDimension($path);
103
-        /** @var RequestHandler $activeRequestHandler */
104
-        $activeRequestHandler = $this->bootstrap->getActiveRequestHandler();
105
-        $parentHttpRequest = $activeRequestHandler->getHttpRequest();
106
-        $uri = RequestInformationHelper::generateBaseUri($parentHttpRequest)->withPath($path);
107
-        $serverRequest = $this->serverRequestFactory->createServerRequest('GET', $uri);
108
-        $routeContext = new RouteContext($serverRequest, RouteParameters::createEmpty());
109
-        try {
110
-            $matchingRoute = $this->router->route($routeContext);
111
-        } catch (NoMatchingRouteException $exception) {
112
-            $matchingRoute = null;
113
-        }
114
-        if (!$matchingRoute) {
115
-            $exception = new \Exception(sprintf('Uri with path "%s" could not be found.', $uri), 1426446160);
116
-            $exceptionHandler = set_exception_handler(null)[0];
117
-            $exceptionHandler->handleException($exception);
118
-            exit();
119
-        }
120
-        $request = ActionRequest::fromHttpRequest($parentHttpRequest);
121
-        foreach ($matchingRoute as $argumentName => $argumentValue) {
122
-            $request->setArgument($argumentName, $argumentValue);
123
-        }
124
-        $response = new ActionResponse();
125
-
126
-        $this->securityContext->withoutAuthorizationChecks(function () use ($request, $response) {
127
-            $this->dispatcher->dispatch($request, $response);
128
-        });
129
-
130
-        return $response->getContent();
131
-    }
132
-
133
-    /**
134
-     * @param string $path
135
-     * @return void
136
-     */
137
-    protected function appendFirstUriPartIfValidDimension(&$path)
138
-    {
139
-        $requestPath = ltrim($this->controllerContext->getRequest()->getHttpRequest()->getUri()->getPath(), '/');
140
-        $matches = [];
141
-        preg_match(FrontendNodeRoutePartHandler::DIMENSION_REQUEST_PATH_MATCHER, $requestPath, $matches);
142
-        if (!isset($matches['firstUriPart']) && !isset($matches['dimensionPresetUriSegments'])) {
143
-            return;
144
-        }
145
-
146
-        $dimensionPresets = $this->contentDimensionPresetSource->getAllPresets();
147
-        if (count($dimensionPresets) === 0) {
148
-            return;
149
-        }
150
-
151
-        $firstUriPartExploded = explode('_', $matches['firstUriPart'] ?: $matches['dimensionPresetUriSegments']);
152
-        if ($this->supportEmptySegmentForDimensions) {
153
-            foreach ($firstUriPartExploded as $uriSegment) {
154
-                $uriSegmentIsValid = false;
155
-                foreach ($dimensionPresets as $dimensionName => $dimensionPreset) {
156
-                    $preset = $this->contentDimensionPresetSource->findPresetByUriSegment($dimensionName, $uriSegment);
157
-                    if ($preset !== null) {
158
-                        $uriSegmentIsValid = true;
159
-                        break;
160
-                    }
161
-                }
162
-                if (!$uriSegmentIsValid) {
163
-                    return;
164
-                }
165
-            }
166
-        } else {
167
-            if (count($firstUriPartExploded) !== count($dimensionPresets)) {
168
-                $this->appendDefaultDimensionPresetUriSegments($dimensionPresets, $path);
169
-                return;
170
-            }
171
-            foreach ($dimensionPresets as $dimensionName => $dimensionPreset) {
172
-                $uriSegment = array_shift($firstUriPartExploded);
173
-                $preset = $this->contentDimensionPresetSource->findPresetByUriSegment($dimensionName, $uriSegment);
174
-                if ($preset === null) {
175
-                    $this->appendDefaultDimensionPresetUriSegments($dimensionPresets, $path);
176
-                    return;
177
-                }
178
-            }
179
-        }
180
-
181
-        $path = $matches['firstUriPart'] . '/' . $path;
182
-    }
183
-
184
-    /**
185
-     * @param array $dimensionPresets
186
-     * @param string $path
187
-     * @return void
188
-     */
189
-    protected function appendDefaultDimensionPresetUriSegments(array $dimensionPresets, &$path) {
190
-        $defaultDimensionPresetUriSegments = [];
191
-        foreach ($dimensionPresets as $dimensionName => $dimensionPreset) {
192
-            $defaultDimensionPresetUriSegments[] = $dimensionPreset['presets'][$dimensionPreset['defaultPreset']]['uriSegment'];
193
-        }
194
-        $path = implode('_', $defaultDimensionPresetUriSegments) . '/' . $path;
195
-    }
85
+	/**
86
+	 * @return void
87
+	 * @throws \Neos\FluidAdaptor\Core\ViewHelper\Exception
88
+	 * @api
89
+	 */
90
+	public function initializeArguments()
91
+	{
92
+		parent::initializeArguments();
93
+		$this->registerArgument('path', 'string', 'Path');
94
+	}
95
+
96
+	/**
97
+	 * @return string
98
+	 * @throws \Exception
99
+	 */
100
+	public function render()
101
+	{
102
+		$this->appendFirstUriPartIfValidDimension($path);
103
+		/** @var RequestHandler $activeRequestHandler */
104
+		$activeRequestHandler = $this->bootstrap->getActiveRequestHandler();
105
+		$parentHttpRequest = $activeRequestHandler->getHttpRequest();
106
+		$uri = RequestInformationHelper::generateBaseUri($parentHttpRequest)->withPath($path);
107
+		$serverRequest = $this->serverRequestFactory->createServerRequest('GET', $uri);
108
+		$routeContext = new RouteContext($serverRequest, RouteParameters::createEmpty());
109
+		try {
110
+			$matchingRoute = $this->router->route($routeContext);
111
+		} catch (NoMatchingRouteException $exception) {
112
+			$matchingRoute = null;
113
+		}
114
+		if (!$matchingRoute) {
115
+			$exception = new \Exception(sprintf('Uri with path "%s" could not be found.', $uri), 1426446160);
116
+			$exceptionHandler = set_exception_handler(null)[0];
117
+			$exceptionHandler->handleException($exception);
118
+			exit();
119
+		}
120
+		$request = ActionRequest::fromHttpRequest($parentHttpRequest);
121
+		foreach ($matchingRoute as $argumentName => $argumentValue) {
122
+			$request->setArgument($argumentName, $argumentValue);
123
+		}
124
+		$response = new ActionResponse();
125
+
126
+		$this->securityContext->withoutAuthorizationChecks(function () use ($request, $response) {
127
+			$this->dispatcher->dispatch($request, $response);
128
+		});
129
+
130
+		return $response->getContent();
131
+	}
132
+
133
+	/**
134
+	 * @param string $path
135
+	 * @return void
136
+	 */
137
+	protected function appendFirstUriPartIfValidDimension(&$path)
138
+	{
139
+		$requestPath = ltrim($this->controllerContext->getRequest()->getHttpRequest()->getUri()->getPath(), '/');
140
+		$matches = [];
141
+		preg_match(FrontendNodeRoutePartHandler::DIMENSION_REQUEST_PATH_MATCHER, $requestPath, $matches);
142
+		if (!isset($matches['firstUriPart']) && !isset($matches['dimensionPresetUriSegments'])) {
143
+			return;
144
+		}
145
+
146
+		$dimensionPresets = $this->contentDimensionPresetSource->getAllPresets();
147
+		if (count($dimensionPresets) === 0) {
148
+			return;
149
+		}
150
+
151
+		$firstUriPartExploded = explode('_', $matches['firstUriPart'] ?: $matches['dimensionPresetUriSegments']);
152
+		if ($this->supportEmptySegmentForDimensions) {
153
+			foreach ($firstUriPartExploded as $uriSegment) {
154
+				$uriSegmentIsValid = false;
155
+				foreach ($dimensionPresets as $dimensionName => $dimensionPreset) {
156
+					$preset = $this->contentDimensionPresetSource->findPresetByUriSegment($dimensionName, $uriSegment);
157
+					if ($preset !== null) {
158
+						$uriSegmentIsValid = true;
159
+						break;
160
+					}
161
+				}
162
+				if (!$uriSegmentIsValid) {
163
+					return;
164
+				}
165
+			}
166
+		} else {
167
+			if (count($firstUriPartExploded) !== count($dimensionPresets)) {
168
+				$this->appendDefaultDimensionPresetUriSegments($dimensionPresets, $path);
169
+				return;
170
+			}
171
+			foreach ($dimensionPresets as $dimensionName => $dimensionPreset) {
172
+				$uriSegment = array_shift($firstUriPartExploded);
173
+				$preset = $this->contentDimensionPresetSource->findPresetByUriSegment($dimensionName, $uriSegment);
174
+				if ($preset === null) {
175
+					$this->appendDefaultDimensionPresetUriSegments($dimensionPresets, $path);
176
+					return;
177
+				}
178
+			}
179
+		}
180
+
181
+		$path = $matches['firstUriPart'] . '/' . $path;
182
+	}
183
+
184
+	/**
185
+	 * @param array $dimensionPresets
186
+	 * @param string $path
187
+	 * @return void
188
+	 */
189
+	protected function appendDefaultDimensionPresetUriSegments(array $dimensionPresets, &$path) {
190
+		$defaultDimensionPresetUriSegments = [];
191
+		foreach ($dimensionPresets as $dimensionName => $dimensionPreset) {
192
+			$defaultDimensionPresetUriSegments[] = $dimensionPreset['presets'][$dimensionPreset['defaultPreset']]['uriSegment'];
193
+		}
194
+		$path = implode('_', $defaultDimensionPresetUriSegments) . '/' . $path;
195
+	}
196 196
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
         }
124 124
         $response = new ActionResponse();
125 125
 
126
-        $this->securityContext->withoutAuthorizationChecks(function () use ($request, $response) {
126
+        $this->securityContext->withoutAuthorizationChecks(function() use ($request, $response) {
127 127
             $this->dispatcher->dispatch($request, $response);
128 128
         });
129 129
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
             }
179 179
         }
180 180
 
181
-        $path = $matches['firstUriPart'] . '/' . $path;
181
+        $path = $matches['firstUriPart'].'/'.$path;
182 182
     }
183 183
 
184 184
     /**
@@ -191,6 +191,6 @@  discard block
 block discarded – undo
191 191
         foreach ($dimensionPresets as $dimensionName => $dimensionPreset) {
192 192
             $defaultDimensionPresetUriSegments[] = $dimensionPreset['presets'][$dimensionPreset['defaultPreset']]['uriSegment'];
193 193
         }
194
-        $path = implode('_', $defaultDimensionPresetUriSegments) . '/' . $path;
194
+        $path = implode('_', $defaultDimensionPresetUriSegments).'/'.$path;
195 195
     }
196 196
 }
Please login to merge, or discard this patch.