@@ -1086,13 +1086,15 @@ public function dispatch($request = null)
1086
1086
}
1087
1087
1088
1088
try {
1089
- if (isset ($ this ->routes [$ method .$ pathInfo ])) {
1090
- return $ this ->handleFoundRoute ([true , $ this ->routes [$ method .$ pathInfo ]['action ' ], []]);
1091
- }
1089
+ return $ this ->sendThroughPipeline ($ this ->middleware , function () use ($ method , $ pathInfo ) {
1090
+ if (isset ($ this ->routes [$ method .$ pathInfo ])) {
1091
+ return $ this ->handleFoundRoute ([true , $ this ->routes [$ method .$ pathInfo ]['action ' ], []]);
1092
+ }
1092
1093
1093
- return $ this ->handleDispatcherResponse (
1094
- $ this ->createDispatcher ()->dispatch ($ method , $ pathInfo )
1095
- );
1094
+ return $ this ->handleDispatcherResponse (
1095
+ $ this ->createDispatcher ()->dispatch ($ method , $ pathInfo )
1096
+ );
1097
+ });
1096
1098
} catch (Exception $ e ) {
1097
1099
return $ this ->sendExceptionToHandler ($ e );
1098
1100
}
@@ -1144,7 +1146,7 @@ protected function handleDispatcherResponse($routeInfo)
1144
1146
}
1145
1147
1146
1148
/**
1147
- * Handle a route that was found by the dispatcher.
1149
+ * Handle a route found by the dispatcher.
1148
1150
*
1149
1151
* @param array $routeInfo
1150
1152
* @return mixed
@@ -1153,32 +1155,14 @@ protected function handleFoundRoute($routeInfo)
1153
1155
{
1154
1156
$ this ->currentRoute = $ routeInfo ;
1155
1157
1156
- // Pipe through global middleware...
1157
- if (count ($ this ->middleware ) > 0 ) {
1158
- return $ this ->prepareResponse ($ this ->sendThroughPipeline ($ this ->middleware , function () use ($ routeInfo ) {
1159
- return $ this ->prepareResponse ($ this ->handleArrayBasedFoundRoute ($ routeInfo ));
1160
- }));
1161
- }
1162
-
1163
- return $ this ->handleArrayBasedFoundRoute ($ routeInfo );
1164
- }
1165
-
1166
- /**
1167
- * Handle an array based route that was found by the dispatcher.
1168
- *
1169
- * @param array $routeInfo
1170
- * @return mixed
1171
- */
1172
- protected function handleArrayBasedFoundRoute ($ routeInfo )
1173
- {
1174
1158
$ action = $ routeInfo [1 ];
1175
1159
1176
1160
// Pipe through route middleware...
1177
1161
if (isset ($ action ['middleware ' ])) {
1178
1162
$ middleware = $ this ->gatherMiddlewareClassNames ($ action ['middleware ' ]);
1179
1163
1180
1164
return $ this ->prepareResponse ($ this ->sendThroughPipeline ($ middleware , function () use ($ routeInfo ) {
1181
- return $ this ->prepareResponse ( $ this -> callActionOnArrayBasedRoute ($ routeInfo) );
1165
+ return $ this ->callActionOnArrayBasedRoute ($ routeInfo );
1182
1166
}));
1183
1167
}
1184
1168
@@ -1324,10 +1308,14 @@ protected function gatherMiddlewareClassNames($middleware)
1324
1308
*/
1325
1309
protected function sendThroughPipeline (array $ middleware , Closure $ then )
1326
1310
{
1327
- return (new Pipeline ($ this ))
1328
- ->send ($ this ->make ('request ' ))
1329
- ->through ($ middleware )
1330
- ->then ($ then );
1311
+ if (count ($ middleware ) > 0 ) {
1312
+ return (new Pipeline ($ this ))
1313
+ ->send ($ this ->make ('request ' ))
1314
+ ->through ($ middleware )
1315
+ ->then ($ then );
1316
+ }
1317
+
1318
+ return $ then ();
1331
1319
}
1332
1320
1333
1321
/**
0 commit comments