private function dispatchRequest(int $requestId): int
    {
        $request = new Request(
            $this->requests[$requestId]['params'],
            $this->requests[$requestId]['stdin']
        );

        try {
            $response = $this->kernel->handleRequest($request);
        } finally {
            $request->cleanUploadedFiles();
        }

        if ($response instanceof ResponseInterface) {
            $this->sendResponse($requestId, $response);
        } elseif ($response instanceof HttpFoundationResponse) {
            $this->sendHttpFoundationResponse($requestId, $response);
        } else {
            throw new \LogicException('Kernel must return a PSR-7 or HttpFoundation response message');
        }

        $this->endRequest($requestId);

        // This method exists on PSR-7 and Symfony responses
        return $response->getStatusCode();
    }