22
33namespace Respect \Rest ;
44
5- use ArrayAccess ;
65use ReflectionFunctionAbstract ;
76use ReflectionParameter ;
8- use RuntimeException ;
97use Respect \Rest \Routes \AbstractRoute ;
108use Respect \Rest \Routines \Routinable ;
119use Respect \Rest \Routines \ProxyableBy ;
1210use Respect \Rest \Routines \ProxyableThrough ;
13- use Respect \Rest \Routines \ProxyableWhen ;
1411use Respect \Rest \Routines \ParamSynced ;
1512
1613/** A routed HTTP Request */
1714class Request
1815{
19-
2016 /** @var string The HTTP method (commonly GET, POST, PUT, DELETE, HEAD) */
2117 public $ method = '' ;
2218
23- /**
19+ /**
2420 * @var array A numeric array containing valid URL parameters. For a route
2521 * path like /users/*, a Request for /users/alganet should have an array
2622 * equivalent to ['alganet']
@@ -35,9 +31,9 @@ class Request
3531
3632 /**
3733 * @param string $method The HTTP method
38- * @param string $uri The called URI
34+ * @param string $uri The called URI
3935 */
40- public function __construct ($ method= null , $ uri= null )
36+ public function __construct ($ method = null , $ uri = null )
4137 {
4238 //Tries to infer request variables only if null
4339 if (is_null ($ method )) {
@@ -82,7 +78,7 @@ protected function prepareForErrorForwards()
8278 foreach ($ this ->route ->sideRoutes as $ sideRoute ) {
8379 if ($ sideRoute instanceof Routes \Error) {
8480 return set_error_handler (
85- function () use ($ sideRoute ) {
81+ function () use ($ sideRoute ) {
8682 $ sideRoute ->errors [] = func_get_args ();
8783 }
8884 );
@@ -167,8 +163,8 @@ protected function processPosRoutines($response)
167163 * Restores the previous error handler if present then check error routes
168164 * for logged errors, forwarding them or returning null silently
169165 *
170- * @param mixed $errorHandler Some error handler (internal or external to
171- * Respect)
166+ * @param mixed $errorHandler Some error handler (internal or external to
167+ * Respect)
172168 *
173169 * @return mixed A route forwarding or a silent null
174170 */
@@ -193,9 +189,9 @@ protected function forwardErrors($errorHandler)
193189 * Does a catch-like operation on an exception based on previously
194190 * declared instances from Router::exceptionRoute
195191 *
196- * @param Exception $e Any exception
192+ * @param Exception $e Any exception
197193 *
198- * @return mixed A route forwarding or a silent null
194+ * @return mixed A route forwarding or a silent null
199195 */
200196 protected function catchExceptions ($ e )
201197 {
@@ -207,6 +203,7 @@ protected function catchExceptions($e)
207203 || $ sideRoute ->class === '\Exception '
208204 ) {
209205 $ sideRoute ->exception = $ e ;
206+
210207 return $ this ->forward ($ sideRoute );
211208 }
212209 }
@@ -222,7 +219,7 @@ public function response()
222219 try {
223220 //No routes, get out
224221 if (!$ this ->route instanceof AbstractRoute) {
225- return null ;
222+ return ;
226223 }
227224
228225 $ errorHandler = $ this ->prepareForErrorForwards ();
@@ -271,7 +268,6 @@ public function response()
271268 public function routineCall ($ type , $ method , Routinable $ routine , &$ params )
272269 {
273270 $ reflection = $ this ->route ->getReflection (
274-
275271 //GET and HEAD are the same for routines
276272 $ method == 'HEAD ' ? 'GET ' : $ method
277273 );
@@ -321,7 +317,7 @@ protected function extractRouteParam(
321317 return $ routeParam ->getDefaultValue ();
322318 }
323319
324- return null ;
320+ return ;
325321 }
326322
327323 /**
@@ -334,7 +330,7 @@ protected function extractRouteParam(
334330 public function forward (AbstractRoute $ route )
335331 {
336332 $ this ->route = $ route ;
333+
337334 return $ this ->response ();
338335 }
339-
340336}
0 commit comments