public function handle($path, $method = null)
    {
        try {
            $match = false;
            foreach ($this->routes as $route) {
                if ($route->match($path, $method)) {
                    $this->lastRoute = $route;
                    $match = true;
                    $results = $route->handle($path, $this->di);
                    if ($results) {
                        return $results;
                    }
                }
            }

            return $this->handleInternal("404", "No route could be matched by the router.");
        } catch (ForbiddenException $e) {
            return $this->handleInternal("403", $e->getMessage());
        } catch (NotFoundException $e) {
            return $this->handleInternal("404", $e->getMessage());
        } catch (InternalErrorException $e) {
            return $this->handleInternal("500", $e->getMessage());
        } catch (\Exception $e) {
            if ($this->mode === Router::DEVELOPMENT) {
                throw $e;
            }
            return $this->handleInternal("500", $e->getMessage());
        }
    }
public function handle($path, $method = null)
    {
        try {
            $match = false;
            foreach ($this->routes as $route) {
                if ($route->match($path, $method)) {
                    $this->lastRoute = $route;
                    $match = true;
                    $results = $route->handle($path, $this->di);
                    if ($results) {
                        return $results;
                    }
                }
            }

            return $this->handleInternal("404", "No route could be matched by the router.");
        } catch (ForbiddenException $e) {
            return $this->handleInternal("403", $e->getMessage());
        } catch (NotFoundException $e) {
            return $this->handleInternal("404", $e->getMessage());
        } catch (InternalErrorException $e) {
            return $this->handleInternal("500", $e->getMessage());
        } catch (\Exception $e) {
            if ($this->mode === Router::DEVELOPMENT) {
                throw $e;
            }
            return $this->handleInternal("500", $e->getMessage());
        }
    }
public function handle ( $ path , $ method = null ) { try { $ match = false ; foreach ( $ this -> routes as $ route ) { if ( $ route -> match ( $ path , $ method ) ) { $ this -> lastRoute = $ route ; $ match = true ; $ results = $ route -> handle ( $ path , $ this -> di ) ; if ( $ results ) { return $ results ; } } } return $ this -> handleInternal ( "404" , "No route could be matched by the router." ) ; } catch ( ForbiddenException $ e ) { return $ this -> handleInternal ( "403" , $ e -> getMessage ( ) ) ; } catch ( NotFoundException $ e ) { return $ this -> handleInternal ( "404" , $ e -> getMessage ( ) ) ; } catch ( InternalErrorException $ e ) { return $ this -> handleInternal ( "500" , $ e -> getMessage ( ) ) ; } catch ( \ Exception $ e ) { if ( $ this -> mode === Router :: DEVELOPMENT ) { throw $ e ; } return $ this -> handleInternal ( "500" , $ e -> getMessage ( ) ) ; } }
Handle the routes and match them towards the request, dispatch them
when a match is made. Each route handler may throw exceptions that
may redirect to an internal route for error handling.
Several routes can match and if the routehandler does not break
execution flow, the route matching will carry on.
Only the last routehandler will get its return value returned further.

@param string $path    the path to find a matching handler for.
@param string $method  the request method to match.

@return mixed content returned from route.
Handle the routes and match them towards the request dispatch them when a match is made . Each route handler may throw exceptions that may redirect to an internal route for error handling . Several routes can match and if the routehandler does not break execution flow the route matching will carry on . Only the last routehandler will get its return value returned further .