src/Router/Router.php
public function dispatch(ServerRequestInterface $request): ServerRequestInterface
    {
        $dispatcher = simpleDispatcher([$this, 'addRoutes']);

        $routeInfo = $dispatcher->dispatch($request->getMethod(), $request->getUri()->getPath());

        if ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
            throw new MethodNotAllowedException($request->getMethod(), $routeInfo[1]);
        }

        if ($routeInfo[0] === Dispatcher::NOT_FOUND) {
            throw new NotFoundHttpException(sprintf("Route '%s' not found.", $request->getUri()->getPath()));
        }

        foreach ($routeInfo[2] as $key => $value) {
            $request = $request->withAttribute($key, $value);
        }

        return $request->withAttribute('route', $this->routes[$routeInfo[1]]);
    }
public function dispatch(ServerRequestInterface $request): ServerRequestInterface
    {
        $dispatcher = simpleDispatcher([$this, 'addRoutes']);

        $routeInfo = $dispatcher->dispatch($request->getMethod(), $request->getUri()->getPath());

        if ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
            throw new MethodNotAllowedException($request->getMethod(), $routeInfo[1]);
        }

        if ($routeInfo[0] === Dispatcher::NOT_FOUND) {
            throw new NotFoundHttpException(sprintf("Route '%s' not found.", $request->getUri()->getPath()));
        }

        foreach ($routeInfo[2] as $key => $value) {
            $request = $request->withAttribute($key, $value);
        }

        return $request->withAttribute('route', $this->routes[$routeInfo[1]]);
    }
public function dispatch ( ServerRequestInterface $ request ) : ServerRequestInterface { $ dispatcher = simpleDispatcher ( [ $ this , 'addRoutes' ] ) ; $ routeInfo = $ dispatcher -> dispatch ( $ request -> getMethod ( ) , $ request -> getUri ( ) -> getPath ( ) ) ; if ( $ routeInfo [ 0 ] === Dispatcher :: METHOD_NOT_ALLOWED ) { throw new MethodNotAllowedException ( $ request -> getMethod ( ) , $ routeInfo [ 1 ] ) ; } if ( $ routeInfo [ 0 ] === Dispatcher :: NOT_FOUND ) { throw new NotFoundHttpException ( sprintf ( "Route '%s' not found." , $ request -> getUri ( ) -> getPath ( ) ) ) ; } foreach ( $ routeInfo [ 2 ] as $ key => $ value ) { $ request = $ request -> withAttribute ( $ key , $ value ) ; } return $ request -> withAttribute ( 'route' , $ this -> routes [ $ routeInfo [ 1 ] ] ) ; }
Dispatches the request to the fast-router
Returns an enriched request with the proper attributes
Throws appropriate exceptions if the route isn't reachable

@param ServerRequestInterface $request

@return ServerRequestInterface
Dispatches the request to the fast - router Returns an enriched request with the proper attributes Throws appropriate exceptions if the route isn t reachable