@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function callAction(string $controller, string $action, array $parameters = []) |
47 | 47 | { |
48 | - try { |
|
48 | + try{ |
|
49 | 49 | $method = new \ReflectionMethod($controller, $action); |
50 | - } catch (\ReflectionException $e) { |
|
50 | + }catch (\ReflectionException $e){ |
|
51 | 51 | throw new ControllerException( |
52 | 52 | "Invalid action `{$controller}`->`{$action}`", |
53 | 53 | ControllerException::BAD_ACTION, |
@@ -55,22 +55,22 @@ discard block |
||
55 | 55 | ); |
56 | 56 | } |
57 | 57 | |
58 | - if ($method->isStatic() || !$method->isPublic()) { |
|
58 | + if ($method->isStatic() || !$method->isPublic()){ |
|
59 | 59 | throw new ControllerException( |
60 | 60 | "Invalid action `{$controller}`->`{$action}`", |
61 | 61 | ControllerException::BAD_ACTION |
62 | 62 | ); |
63 | 63 | } |
64 | 64 | |
65 | - try { |
|
65 | + try{ |
|
66 | 66 | // getting the set of arguments should be sent to requested method |
67 | 67 | $args = $this->resolver->resolveArguments($method, $parameters); |
68 | - } catch (ArgumentException $e) { |
|
68 | + }catch (ArgumentException $e){ |
|
69 | 69 | throw new ControllerException( |
70 | 70 | "Missing/invalid parameter '{$e->getParameter()->name}' of `{$controller}`->`{$action}`", |
71 | 71 | ControllerException::BAD_ARGUMENT |
72 | 72 | ); |
73 | - } catch (ContainerExceptionInterface $e) { |
|
73 | + }catch (ContainerExceptionInterface $e){ |
|
74 | 74 | throw new ControllerException( |
75 | 75 | $e->getMessage(), |
76 | 76 | ControllerException::ERROR, |
@@ -42,9 +42,12 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function callAction(string $controller, string $action, array $parameters = []) |
44 | 44 | { |
45 | - try { |
|
45 | + try |
|
46 | + { |
|
46 | 47 | $method = new \ReflectionMethod($controller, $action); |
47 | - } catch (\ReflectionException $e) { |
|
48 | + } |
|
49 | + catch (\ReflectionException $e) |
|
50 | + { |
|
48 | 51 | throw new ControllerException( |
49 | 52 | "Invalid action `{$controller}`->`{$action}`", |
50 | 53 | ControllerException::BAD_ACTION, |
@@ -52,22 +55,28 @@ discard block |
||
52 | 55 | ); |
53 | 56 | } |
54 | 57 | |
55 | - if ($method->isStatic() || !$method->isPublic()) { |
|
58 | + if ($method->isStatic() || !$method->isPublic()) |
|
59 | + { |
|
56 | 60 | throw new ControllerException( |
57 | 61 | "Invalid action `{$controller}`->`{$action}`", |
58 | 62 | ControllerException::BAD_ACTION |
59 | 63 | ); |
60 | 64 | } |
61 | 65 | |
62 | - try { |
|
66 | + try |
|
67 | + { |
|
63 | 68 | // getting the set of arguments should be sent to requested method |
64 | 69 | $args = $this->resolver->resolveArguments($method, $parameters); |
65 | - } catch (ArgumentException $e) { |
|
70 | + } |
|
71 | + catch (ArgumentException $e) |
|
72 | + { |
|
66 | 73 | throw new ControllerException( |
67 | 74 | "Missing/invalid parameter '{$e->getParameter()->name}' of `{$controller}`->`{$action}`", |
68 | 75 | ControllerException::BAD_ARGUMENT |
69 | 76 | ); |
70 | - } catch (ContainerExceptionInterface $e) { |
|
77 | + } |
|
78 | + catch (ContainerExceptionInterface $e) |
|
79 | + { |
|
71 | 80 | throw new ControllerException( |
72 | 81 | $e->getMessage(), |
73 | 82 | ControllerException::ERROR, |
@@ -103,9 +103,9 @@ |
||
103 | 103 | $this->assertSame('echoed', (string)$response->getBody()); |
104 | 104 | |
105 | 105 | $e = null; |
106 | - try { |
|
106 | + try{ |
|
107 | 107 | $router->handle(new ServerRequest([], [], new Uri('/test'))); |
108 | - } catch (UndefinedRouteException $e) { |
|
108 | + }catch (UndefinedRouteException $e){ |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | $this->assertNotNull($e, 'Autofill not fired'); |
@@ -103,9 +103,12 @@ |
||
103 | 103 | $this->assertSame('echoed', (string)$response->getBody()); |
104 | 104 | |
105 | 105 | $e = null; |
106 | - try { |
|
106 | + try |
|
107 | + { |
|
107 | 108 | $router->handle(new ServerRequest([], [], new Uri('/test'))); |
108 | - } catch (UndefinedRouteException $e) { |
|
109 | + } |
|
110 | + catch (UndefinedRouteException $e) |
|
111 | + { |
|
109 | 112 | } |
110 | 113 | |
111 | 114 | $this->assertNotNull($e, 'Autofill not fired'); |
@@ -37,7 +37,7 @@ |
||
37 | 37 | $response = new Response('php://memory', $code, []); |
38 | 38 | $response = $response->withStatus($code, $reasonPhrase); |
39 | 39 | |
40 | - foreach ($this->config->getBaseHeaders() as $header => $value) { |
|
40 | + foreach ($this->config->getBaseHeaders() as $header => $value){ |
|
41 | 41 | $response = $response->withAddedHeader($header, $value); |
42 | 42 | } |
43 | 43 |
@@ -37,7 +37,8 @@ |
||
37 | 37 | $response = new Response('php://memory', $code, []); |
38 | 38 | $response = $response->withStatus($code, $reasonPhrase); |
39 | 39 | |
40 | - foreach ($this->config->getBaseHeaders() as $header => $value) { |
|
40 | + foreach ($this->config->getBaseHeaders() as $header => $value) |
|
41 | + { |
|
41 | 42 | $response = $response->withAddedHeader($header, $value); |
42 | 43 | } |
43 | 44 |
@@ -26,7 +26,7 @@ |
||
26 | 26 | string $clientFilename = null, |
27 | 27 | string $clientMediaType = null |
28 | 28 | ): UploadedFileInterface { |
29 | - if ($size === null) { |
|
29 | + if ($size === null){ |
|
30 | 30 | $size = $stream->getSize(); |
31 | 31 | } |
32 | 32 |
@@ -26,7 +26,8 @@ |
||
26 | 26 | string $clientFilename = null, |
27 | 27 | string $clientMediaType = null |
28 | 28 | ): UploadedFileInterface { |
29 | - if ($size === null) { |
|
29 | + if ($size === null) |
|
30 | + { |
|
30 | 31 | $size = $stream->getSize(); |
31 | 32 | } |
32 | 33 |
@@ -27,7 +27,7 @@ |
||
27 | 27 | $router = $this->makeRouter(); |
28 | 28 | $router->setRoute( |
29 | 29 | 'action', |
30 | - new Route('/something', function () { |
|
30 | + new Route('/something', function (){ |
|
31 | 31 | return 'hello world'; |
32 | 32 | }) |
33 | 33 | ); |
@@ -27,7 +27,8 @@ |
||
27 | 27 | $router = $this->makeRouter(); |
28 | 28 | $router->setRoute( |
29 | 29 | 'action', |
30 | - new Route('/something', function () { |
|
30 | + new Route('/something', function () |
|
31 | + { |
|
31 | 32 | return 'hello world'; |
32 | 33 | }) |
33 | 34 | ); |
@@ -24,6 +24,6 @@ |
||
24 | 24 | |
25 | 25 | public function callAction(string $controller, string $action = null, array $parameters = []) |
26 | 26 | { |
27 | - return '@wrapped.' . $this->core->callAction($controller, $action, $parameters); |
|
27 | + return '@wrapped.'.$this->core->callAction($controller, $action, $parameters); |
|
28 | 28 | } |
29 | 29 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct(string $controller, $action, int $options = 0) |
41 | 41 | { |
42 | - if (!is_string($action) && !is_array($action)) { |
|
42 | + if (!is_string($action) && !is_array($action)){ |
|
43 | 43 | throw new InvalidArgumentException( |
44 | 44 | sprintf( |
45 | 45 | 'Action parameter must type string or array, `%s` given', |
@@ -51,13 +51,13 @@ discard block |
||
51 | 51 | $this->controller = $controller; |
52 | 52 | $this->action = $action; |
53 | 53 | |
54 | - if (is_string($action)) { |
|
54 | + if (is_string($action)){ |
|
55 | 55 | parent::__construct( |
56 | 56 | ['action' => $action], |
57 | 57 | ['action' => new Autofill($action)], |
58 | 58 | $options |
59 | 59 | ); |
60 | - } else { |
|
60 | + }else{ |
|
61 | 61 | parent::__construct( |
62 | 62 | ['action' => null], |
63 | 63 | ['action' => $action], |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | protected function resolveAction(array $matches): string |
81 | 81 | { |
82 | 82 | $action = $this->action; |
83 | - if (is_string($action)) { |
|
83 | + if (is_string($action)){ |
|
84 | 84 | return $action; |
85 | 85 | } |
86 | 86 |
@@ -39,7 +39,8 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct(string $controller, $action, int $options = 0) |
41 | 41 | { |
42 | - if (!is_string($action) && !is_array($action)) { |
|
42 | + if (!is_string($action) && !is_array($action)) |
|
43 | + { |
|
43 | 44 | throw new InvalidArgumentException( |
44 | 45 | sprintf( |
45 | 46 | 'Action parameter must type string or array, `%s` given', |
@@ -51,13 +52,16 @@ discard block |
||
51 | 52 | $this->controller = $controller; |
52 | 53 | $this->action = $action; |
53 | 54 | |
54 | - if (is_string($action)) { |
|
55 | + if (is_string($action)) |
|
56 | + { |
|
55 | 57 | parent::__construct( |
56 | 58 | ['action' => $action], |
57 | 59 | ['action' => new Autofill($action)], |
58 | 60 | $options |
59 | 61 | ); |
60 | - } else { |
|
62 | + } |
|
63 | + else |
|
64 | + { |
|
61 | 65 | parent::__construct( |
62 | 66 | ['action' => null], |
63 | 67 | ['action' => $action], |
@@ -80,7 +84,8 @@ discard block |
||
80 | 84 | protected function resolveAction(array $matches): string |
81 | 85 | { |
82 | 86 | $action = $this->action; |
83 | - if (is_string($action)) { |
|
87 | + if (is_string($action)) |
|
88 | + { |
|
84 | 89 | return $action; |
85 | 90 | } |
86 | 91 |
@@ -58,7 +58,8 @@ |
||
58 | 58 | */ |
59 | 59 | protected function resolveController(array $matches): string |
60 | 60 | { |
61 | - if (preg_match('/[^a-z_0-9\-]/i', $matches['controller'])) { |
|
61 | + if (preg_match('/[^a-z_0-9\-]/i', $matches['controller'])) |
|
62 | + { |
|
62 | 63 | throw new TargetException('Invalid namespace target, controller name not allowed.'); |
63 | 64 | } |
64 | 65 |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | string $namespace, |
34 | 34 | string $postfix = 'Controller', |
35 | 35 | int $options = 0 |
36 | - ) { |
|
36 | + ){ |
|
37 | 37 | $this->namespace = rtrim($namespace, '\\'); |
38 | 38 | $this->postfix = ucfirst($postfix); |
39 | 39 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | protected function resolveController(array $matches): string |
53 | 53 | { |
54 | - if (preg_match('/[^a-z_0-9\-]/i', $matches['controller'])) { |
|
54 | + if (preg_match('/[^a-z_0-9\-]/i', $matches['controller'])){ |
|
55 | 55 | throw new TargetException('Invalid namespace target, controller name not allowed.'); |
56 | 56 | } |
57 | 57 |
@@ -69,13 +69,17 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function handle(ServerRequestInterface $request): ResponseInterface |
71 | 71 | { |
72 | - try { |
|
72 | + try |
|
73 | + { |
|
73 | 74 | $route = $this->matchRoute($request, $routeName); |
74 | - } catch (RouteException $e) { |
|
75 | + } |
|
76 | + catch (RouteException $e) |
|
77 | + { |
|
75 | 78 | throw new RouterException('Invalid route definition', $e->getCode(), $e); |
76 | 79 | } |
77 | 80 | |
78 | - if ($route === null) { |
|
81 | + if ($route === null) |
|
82 | + { |
|
79 | 83 | throw new RouteNotFoundException($request->getUri()); |
80 | 84 | } |
81 | 85 | |
@@ -120,7 +124,8 @@ discard block |
||
120 | 124 | */ |
121 | 125 | public function getRoute(string $name): RouteInterface |
122 | 126 | { |
123 | - if (isset($this->routes[$name])) { |
|
127 | + if (isset($this->routes[$name])) |
|
128 | + { |
|
124 | 129 | return $this->routes[$name]; |
125 | 130 | } |
126 | 131 | |
@@ -132,7 +137,8 @@ discard block |
||
132 | 137 | */ |
133 | 138 | public function getRoutes(): array |
134 | 139 | { |
135 | - if (!empty($this->default)) { |
|
140 | + if (!empty($this->default)) |
|
141 | + { |
|
136 | 142 | return $this->routes + [null => $this->default]; |
137 | 143 | } |
138 | 144 | |
@@ -144,9 +150,12 @@ discard block |
||
144 | 150 | */ |
145 | 151 | public function uri(string $route, $parameters = []): UriInterface |
146 | 152 | { |
147 | - try { |
|
153 | + try |
|
154 | + { |
|
148 | 155 | return $this->getRoute($route)->uri($parameters); |
149 | - } catch (UndefinedRouteException $e) { |
|
156 | + } |
|
157 | + catch (UndefinedRouteException $e) |
|
158 | + { |
|
150 | 159 | //In some cases route name can be provided as controller:action pair, we can try to |
151 | 160 | //generate such route automatically based on our default/fallback route |
152 | 161 | return $this->castRoute($route)->uri($parameters); |
@@ -161,17 +170,20 @@ discard block |
||
161 | 170 | */ |
162 | 171 | protected function matchRoute(ServerRequestInterface $request, string &$routeName = null): ?RouteInterface |
163 | 172 | { |
164 | - foreach ($this->routes as $name => $route) { |
|
173 | + foreach ($this->routes as $name => $route) |
|
174 | + { |
|
165 | 175 | // Matched route will return new route instance with matched parameters |
166 | 176 | $matched = $route->match($request); |
167 | 177 | |
168 | - if ($matched !== null) { |
|
178 | + if ($matched !== null) |
|
179 | + { |
|
169 | 180 | $routeName = $name; |
170 | 181 | return $matched; |
171 | 182 | } |
172 | 183 | } |
173 | 184 | |
174 | - if ($this->default !== null) { |
|
185 | + if ($this->default !== null) |
|
186 | + { |
|
175 | 187 | return $this->default->match($request); |
176 | 188 | } |
177 | 189 | |
@@ -187,7 +199,8 @@ discard block |
||
187 | 199 | */ |
188 | 200 | protected function configure(RouteInterface $route): RouteInterface |
189 | 201 | { |
190 | - if ($route instanceof ContainerizedInterface && !$route->hasContainer()) { |
|
202 | + if ($route instanceof ContainerizedInterface && !$route->hasContainer()) |
|
203 | + { |
|
191 | 204 | // isolating route in a given container |
192 | 205 | $route = $route->withContainer($this->container); |
193 | 206 | } |
@@ -220,11 +233,16 @@ discard block |
||
220 | 233 | ); |
221 | 234 | } |
222 | 235 | |
223 | - if (!empty($matches['name'])) { |
|
236 | + if (!empty($matches['name'])) |
|
237 | + { |
|
224 | 238 | $routeObject = $this->getRoute($matches['name']); |
225 | - } elseif ($this->default !== null) { |
|
239 | + } |
|
240 | + elseif ($this->default !== null) |
|
241 | + { |
|
226 | 242 | $routeObject = $this->default; |
227 | - } else { |
|
243 | + } |
|
244 | + else |
|
245 | + { |
|
228 | 246 | throw new UndefinedRouteException("Unable to locate route candidate for `{$route}`"); |
229 | 247 | } |
230 | 248 |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | public function __construct(string $basePath, UriHandler $uriHandler, ContainerInterface $container) |
53 | 53 | { |
54 | - $this->basePath = '/' . ltrim($basePath, '/'); |
|
54 | + $this->basePath = '/'.ltrim($basePath, '/'); |
|
55 | 55 | $this->uriHandler = $uriHandler; |
56 | 56 | $this->container = $container; |
57 | 57 | } |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function handle(ServerRequestInterface $request): ResponseInterface |
66 | 66 | { |
67 | - try { |
|
67 | + try{ |
|
68 | 68 | $route = $this->matchRoute($request, $routeName); |
69 | - } catch (RouteException $e) { |
|
69 | + }catch (RouteException $e){ |
|
70 | 70 | throw new RouterException('Invalid route definition', $e->getCode(), $e); |
71 | 71 | } |
72 | 72 | |
73 | - if ($route === null) { |
|
73 | + if ($route === null){ |
|
74 | 74 | throw new RouteNotFoundException($request->getUri()); |
75 | 75 | } |
76 | 76 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function getRoute(string $name): RouteInterface |
117 | 117 | { |
118 | - if (isset($this->routes[$name])) { |
|
118 | + if (isset($this->routes[$name])){ |
|
119 | 119 | return $this->routes[$name]; |
120 | 120 | } |
121 | 121 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function getRoutes(): array |
129 | 129 | { |
130 | - if (!empty($this->default)) { |
|
130 | + if (!empty($this->default)){ |
|
131 | 131 | return $this->routes + [null => $this->default]; |
132 | 132 | } |
133 | 133 | |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function uri(string $route, $parameters = []): UriInterface |
141 | 141 | { |
142 | - try { |
|
142 | + try{ |
|
143 | 143 | return $this->getRoute($route)->uri($parameters); |
144 | - } catch (UndefinedRouteException $e) { |
|
144 | + }catch (UndefinedRouteException $e){ |
|
145 | 145 | //In some cases route name can be provided as controller:action pair, we can try to |
146 | 146 | //generate such route automatically based on our default/fallback route |
147 | 147 | return $this->castRoute($route)->uri($parameters); |
@@ -153,17 +153,17 @@ discard block |
||
153 | 153 | */ |
154 | 154 | protected function matchRoute(ServerRequestInterface $request, string &$routeName = null): ?RouteInterface |
155 | 155 | { |
156 | - foreach ($this->routes as $name => $route) { |
|
156 | + foreach ($this->routes as $name => $route){ |
|
157 | 157 | // Matched route will return new route instance with matched parameters |
158 | 158 | $matched = $route->match($request); |
159 | 159 | |
160 | - if ($matched !== null) { |
|
160 | + if ($matched !== null){ |
|
161 | 161 | $routeName = $name; |
162 | 162 | return $matched; |
163 | 163 | } |
164 | 164 | } |
165 | 165 | |
166 | - if ($this->default !== null) { |
|
166 | + if ($this->default !== null){ |
|
167 | 167 | return $this->default->match($request); |
168 | 168 | } |
169 | 169 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | */ |
177 | 177 | protected function configure(RouteInterface $route): RouteInterface |
178 | 178 | { |
179 | - if ($route instanceof ContainerizedInterface && !$route->hasContainer()) { |
|
179 | + if ($route instanceof ContainerizedInterface && !$route->hasContainer()){ |
|
180 | 180 | // isolating route in a given container |
181 | 181 | $route = $route->withContainer($this->container); |
182 | 182 | } |
@@ -201,17 +201,17 @@ discard block |
||
201 | 201 | $route, |
202 | 202 | $matches |
203 | 203 | ) |
204 | - ) { |
|
204 | + ){ |
|
205 | 205 | throw new UndefinedRouteException( |
206 | 206 | "Unable to locate route or use default route with 'name/controller:action' pattern" |
207 | 207 | ); |
208 | 208 | } |
209 | 209 | |
210 | - if (!empty($matches['name'])) { |
|
210 | + if (!empty($matches['name'])){ |
|
211 | 211 | $routeObject = $this->getRoute($matches['name']); |
212 | - } elseif ($this->default !== null) { |
|
212 | + } elseif ($this->default !== null){ |
|
213 | 213 | $routeObject = $this->default; |
214 | - } else { |
|
214 | + }else{ |
|
215 | 215 | throw new UndefinedRouteException("Unable to locate route candidate for `{$route}`"); |
216 | 216 | } |
217 | 217 |