public function dispatch(Request $request)
    {
        if (ltrim($_SERVER['REQUEST_URI'], '/') === '') {
            return new DispatcherResult(200, $this->defaultHandler);
        }

        $dispatcher = $this->getDispatcher();

        $match = $dispatcher->dispatch($request->getMethod(), $_SERVER['REQUEST_URI']);

        $code = null;
        $handler = null;

        switch ($match[0]) {
            case Dispatcher::NOT_FOUND:
                $code = 404;
                $handler = $this->errorHandlers[$code];
                break;
            case Dispatcher::METHOD_NOT_ALLOWED:
                $code = 405;
                $handler = $this->errorHandlers[$code];
                $handler->setSuppliedParameters(['allowedMethods' => $match[1]]);
                break;
            case Dispatcher::FOUND:
                $code = 200;
                /** @var RouteCallbackDTOInterface $handler */
                $handler = $match[1];
                $handler->setSuppliedParameters($match[2]);
                break;
        }

        if ($code !== null) {
            return new DispatcherResult($code, $handler);
        }

        return new DispatcherResult(200, $this->defaultHandler);
    }
public function dispatch(Request $request)
    {
        if (ltrim($_SERVER['REQUEST_URI'], '/') === '') {
            return new DispatcherResult(200, $this->defaultHandler);
        }

        $dispatcher = $this->getDispatcher();

        $match = $dispatcher->dispatch($request->getMethod(), $_SERVER['REQUEST_URI']);

        $code = null;
        $handler = null;

        switch ($match[0]) {
            case Dispatcher::NOT_FOUND:
                $code = 404;
                $handler = $this->errorHandlers[$code];
                break;
            case Dispatcher::METHOD_NOT_ALLOWED:
                $code = 405;
                $handler = $this->errorHandlers[$code];
                $handler->setSuppliedParameters(['allowedMethods' => $match[1]]);
                break;
            case Dispatcher::FOUND:
                $code = 200;
                /** @var RouteCallbackDTOInterface $handler */
                $handler = $match[1];
                $handler->setSuppliedParameters($match[2]);
                break;
        }

        if ($code !== null) {
            return new DispatcherResult($code, $handler);
        }

        return new DispatcherResult(200, $this->defaultHandler);
    }
public function dispatch ( Request $ request ) { if ( ltrim ( $ _SERVER [ 'REQUEST_URI' ] , '/' ) === '' ) { return new DispatcherResult ( 200 , $ this -> defaultHandler ) ; } $ dispatcher = $ this -> getDispatcher ( ) ; $ match = $ dispatcher -> dispatch ( $ request -> getMethod ( ) , $ _SERVER [ 'REQUEST_URI' ] ) ; $ code = null ; $ handler = null ; switch ( $ match [ 0 ] ) { case Dispatcher :: NOT_FOUND : $ code = 404 ; $ handler = $ this -> errorHandlers [ $ code ] ; break ; case Dispatcher :: METHOD_NOT_ALLOWED : $ code = 405 ; $ handler = $ this -> errorHandlers [ $ code ] ; $ handler -> setSuppliedParameters ( [ 'allowedMethods' => $ match [ 1 ] ] ) ; break ; case Dispatcher :: FOUND : $ code = 200 ; /** @var RouteCallbackDTOInterface $handler */ $ handler = $ match [ 1 ] ; $ handler -> setSuppliedParameters ( $ match [ 2 ] ) ; break ; } if ( $ code !== null ) { return new DispatcherResult ( $ code , $ handler ) ; } return new DispatcherResult ( 200 , $ this -> defaultHandler ) ; }
Once called the router should examine the current request by request method and url
and find a matching route. If no route was find dispatch a http error instead.

Dispatch means in this context that the router will use the RouteCallbackDTO in the Route
and call the controller with the correct action and pass the parameters.

@param Request $request
@return DispatcherResultInterface
Once called the router should examine the current request by request method and url and find a matching route . If no route was find dispatch a http error instead .