| Total Complexity | 7 |
| Total Lines | 54 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 8 | class MatchedRoute |
||
| 9 | { |
||
| 10 | public static $chainData; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Handle an incoming request. |
||
| 14 | * |
||
| 15 | * @param \Illuminate\Http\Request $request |
||
| 16 | * @param \Closure $next |
||
| 17 | * |
||
| 18 | * @return mixed |
||
| 19 | */ |
||
| 20 | public function handle($request, Closure $next) |
||
| 21 | { |
||
| 22 | $route = $request->route(); |
||
| 23 | $matchedRoute = $this->getMatchedRouteInto($route); |
||
| 24 | $matchedCallbacks = []; |
||
| 25 | foreach ($matchedRoute as $info) { |
||
| 26 | foreach (static::$chainData as $routeInfo => $callBacks) { |
||
| 27 | if (Str::is($routeInfo, $info)) { |
||
| 28 | $matchedCallbacks[] = array_pop($callBacks); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | $this->exec($matchedCallbacks); |
||
| 34 | |||
| 35 | return $next($request); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param array $closures |
||
| 40 | */ |
||
| 41 | private function exec(array $closures) |
||
| 42 | { |
||
| 43 | foreach (array_flatten($closures) as $closure) { |
||
| 44 | $closure(); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param $route |
||
| 50 | * |
||
| 51 | * @return array |
||
| 52 | */ |
||
| 53 | private function getMatchedRouteInto($route): array |
||
| 62 | } |
||
| 63 | } |
||
| 64 |