public function handleRequest(Request $request): Promise {
        $method = $request->getMethod();
        $path = \rawurldecode($request->getUri()->getPath());

        $toMatch = "{$method}\0{$path}";

        if (null === $match = $this->cache->get($toMatch)) {
            $match = $this->routeDispatcher->dispatch($method, $path);
            $this->cache->put($toMatch, $match);
        }

        switch ($match[0]) {
            case Dispatcher::FOUND:
                /**
                 * @var RequestHandler $requestHandler
                 * @var string[] $routeArgs
                 */
                list(, $requestHandler, $routeArgs) = $match;
                $request->setAttribute(self::class, $routeArgs);

                return $requestHandler->handleRequest($request);

            case Dispatcher::NOT_FOUND:
                if ($this->fallback !== null) {
                    return $this->fallback->handleRequest($request);
                }

                return $this->makeNotFoundResponse($request);

            case Dispatcher::METHOD_NOT_ALLOWED:
                return $this->makeMethodNotAllowedResponse($match[1], $request);

            default:
                // @codeCoverageIgnoreStart
                throw new \UnexpectedValueException(
                    "Encountered unexpected dispatcher code: " . $match[0]
                );
                // @codeCoverageIgnoreEnd
        }
    }
public function handleRequest(Request $request): Promise {
        $method = $request->getMethod();
        $path = \rawurldecode($request->getUri()->getPath());

        $toMatch = "{$method}\0{$path}";

        if (null === $match = $this->cache->get($toMatch)) {
            $match = $this->routeDispatcher->dispatch($method, $path);
            $this->cache->put($toMatch, $match);
        }

        switch ($match[0]) {
            case Dispatcher::FOUND:
                /**
                 * @var RequestHandler $requestHandler
                 * @var string[] $routeArgs
                 */
                list(, $requestHandler, $routeArgs) = $match;
                $request->setAttribute(self::class, $routeArgs);

                return $requestHandler->handleRequest($request);

            case Dispatcher::NOT_FOUND:
                if ($this->fallback !== null) {
                    return $this->fallback->handleRequest($request);
                }

                return $this->makeNotFoundResponse($request);

            case Dispatcher::METHOD_NOT_ALLOWED:
                return $this->makeMethodNotAllowedResponse($match[1], $request);

            default:
                // @codeCoverageIgnoreStart
                throw new \UnexpectedValueException(
                    "Encountered unexpected dispatcher code: " . $match[0]
                );
                // @codeCoverageIgnoreEnd
        }
    }
public function handleRequest ( Request $ request ) : Promise { $ method = $ request -> getMethod ( ) ; $ path = \ rawurldecode ( $ request -> getUri ( ) -> getPath ( ) ) ; $ toMatch = "{$method}\0{$path}" ; if ( null === $ match = $ this -> cache -> get ( $ toMatch ) ) { $ match = $ this -> routeDispatcher -> dispatch ( $ method , $ path ) ; $ this -> cache -> put ( $ toMatch , $ match ) ; } switch ( $ match [ 0 ] ) { case Dispatcher :: FOUND : /**
                 * @var RequestHandler $requestHandler
                 * @var string[] $routeArgs
                 */ list ( , $ requestHandler , $ routeArgs ) = $ match ; $ request -> setAttribute ( self :: class , $ routeArgs ) ; return $ requestHandler -> handleRequest ( $ request ) ; case Dispatcher :: NOT_FOUND : if ( $ this -> fallback !== null ) { return $ this -> fallback -> handleRequest ( $ request ) ; } return $ this -> makeNotFoundResponse ( $ request ) ; case Dispatcher :: METHOD_NOT_ALLOWED : return $ this -> makeMethodNotAllowedResponse ( $ match [ 1 ] , $ request ) ; default : // @codeCoverageIgnoreStart throw new \ UnexpectedValueException ( "Encountered unexpected dispatcher code: " . $ match [ 0 ] ) ; // @codeCoverageIgnoreEnd } }
Route a request and dispatch it to the appropriate handler.

@param Request $request

@return Promise<\Amp\Http\Server\Response>
Route a request and dispatch it to the appropriate handler .