public function dispatch(ServerRequestInterface $request, ResponseInterface $response)
    {

        $method = $request->getMethod();
        $uri = $request->getUri()->getPath();

        $d = new \FastRoute\Dispatcher\GroupCountBased($this->collector->getData());
        $r = $d->dispatch(
            ($method === 'HEAD' ? 'GET' : $method),
            $uri
        );

        switch ($r[0]) {
            case 0:
                throw new NotFoundException('Route not found');
                break;
            case 1:
                return call_user_func($r[1], $request, $response, $r[2]);
                break;
            case 2:
                throw new MethodNotAllowedException('Method not allowed', 0, null, $r[1]);
                break;
        }

        return $response;
    }