/** * Dispatch the URI to the matched route. * * @return void */ public function dispatch() { $routesList = \Route::getRoutesList(); foreach ($routesList as $key => $value) { $routeWithPattern = str_replace("{id}", "[0-9]+", $key); $routeWithPattern = str_replace("{name}", "[a-zA-Z_ ]+", $routeWithPattern); $routeWithPattern = str_replace('/', '\\/', ltrim($routeWithPattern, '/')); $regex = '/\\/' . $routeWithPattern . '(\\/|)$/'; if (preg_match($regex, $this->routeName, $matches)) { if ($matches[0] == $this->routeName) { $matchedRouteName = $key; } } } if (isset($matchedRouteName) && in_array($this->httpMethod, $routesList[$matchedRouteName]['verbs']) && array_key_exists($matchedRouteName, $routesList)) { $this->setParams($matchedRouteName); \Route::call($matchedRouteName); } elseif (isset($matchedRouteName) && !in_array($this->httpMethod, $routesList[$matchedRouteName]['verbs']) && array_key_exists($matchedRouteName, $routesList)) { throw new MethodNotAllowedException('405 Method Not Allowed'); } else { throw new NotFoundException('404 Not Found'); } }