route icon indicating copy to clipboard operation
route copied to clipboard

Dispatcher: handle and find

Open vanodevium opened this issue 1 year ago • 1 comments

Is there any way to only find the specific handler, but not handle it?

In simple way, this is original dispatchRequest()

    public function dispatchRequest(ServerRequestInterface $request): ResponseInterface
    {
        $method = $request->getMethod();
        $uri    = $request->getUri()->getPath();
        $match  = $this->dispatch($method, $uri);

        switch ($match[0]) {
            case FastRoute::NOT_FOUND:
                $this->setNotFoundDecoratorMiddleware();
                break;
            case FastRoute::METHOD_NOT_ALLOWED:
                $allowed = (array) $match[1];
                $this->setMethodNotAllowedDecoratorMiddleware($allowed);
                break;
            case FastRoute::FOUND:
                $route = $this->ensureHandlerIsRoute($match[1], $method, $uri)->setVars($match[2]);

                if ($this->isExtraConditionMatch($route, $request)) {
                    $this->setFoundMiddleware($route);
                    $request = $this->requestWithRouteAttributes($request, $route);
                    break;
                }

                $this->setNotFoundDecoratorMiddleware();
                break;
        }

        return $this->handle($request);
    }

But I wanna method which return only $match array, without processing. Something like:

    public function dispatchAndReturn(ServerRequestInterface $request): array
    {
        $method = $request->getMethod();
        $uri    = $request->getUri()->getPath();
        return $this->dispatch($method, $uri);
    }

vanodevium avatar Jan 08 '23 14:01 vanodevium