Converts a problem to a provided Response, without the format-sensitive bits.

@param ApiProblem $problem
The problem to convert.

@return ResponseInterface
The appropriate response object.
488352
protected function toResponse(ApiProblem $problem) : ResponseInterface
    {
        $status = $problem->getStatus() ?: 500;

        $response = $this->responseFactory->createResponse($status);

        return $response;
    }
665223
private function withError(ResponseInterface $response, $throwable)
    {
        $detail = 'Internal Server Error';
        $extensions = [];

        if ($this->displayErrorDetails) {
            $throwables = $this->unpackThrowables($throwable);
            $extensions['error_details'] = $this->formatStacktraceForExceptions($throwables);

            $detail = $throwable->getMessage();
        }

        $problem = new HTTPProblem(500, $detail, $extensions);
        return $this->renderProblem($response, $this->renderer, $problem);
    }
886165
protected function send(
        ResponseInterface $response,
        string $body): ResponseInterface
    {
        if (!$body) {
            $response = $this->sendErrorDocument($response);
        }
        unset($this->errorDocument);
        $response = $response->withHeader(
            Response::HEADER_CONTENT_LENGTH,
            (string) strlen($body));
        header(Response::PROTOCOL
             . $response->getProtocolVersion() . " "
             . $response->getStatusCode() . " "
             . $response->getReasonPhrase());
        foreach ($response->getHeaders() as $key => $value) {
            header($key . ": " . implode("; ", $value));
        }
        $response->getBody()->write($body);
        return $response;
    }
235878
private function formatProblem(string $problem) : string
    {
        $lines  = explode(PHP_EOL, $problem);
        $amount = count($lines);

        for ($i = 1; $i < $amount; $i++) {
            $lines[$i] = '    ' . $lines[$i];
        }

        return implode(PHP_EOL, $lines);
    }
633574
public function handle($request) : ResponseInterface
    {
        $this->setRouter($request);

        try {
            $response = $this->sendRequestThroughRouter($request);
            /*
             * Check whether return value is a instance of Response,
             * otherwise we will try to fetch the response form container,
             * create a response and return to the browser.
             *
             */
            if (!$response instanceof ResponseInterface && !is_array($response)) {
                $r = $this->container->has('response') ? $this->container->get('response') : '';
                $response = Response::make($r);
            }
        } catch (\Exception $e) {
            $this->handleException($e);
        } catch (Throwable $e) {
            $this->handleException($e);
        }

        return $response;
    }
95092
public function send(ConversionInterface $conversion): ResponseInterface
    {
        if (!$conversion instanceof Conversion) {
            throw new UnsupportedConversionTypeException($this, $conversion);
        }

        $previousSentConversion = $this->repository->pull(
            $conversion->getId(),
            get_class($conversion)
        );
        if ($previousSentConversion instanceof StoredConversionInterface) {
            throw new DuplicatedConversionException($conversion);
        }

        $request = new Request("get", $this->getPath($conversion));
        $response = $this->client->send($request);

        $this->repository->push($conversion, $response);
        return $response;
    }
403753
protected function convertResponse(ResponseInterface $response)
    {
        $this->response->setContent($response->getBody());
        $this->response->setStatusCode($response->getStatusCode());
        foreach ($response->getHeaders() as $name => $values) {
            $this->response->setHeader($name, implode(', ', $values));
        }

        return $this->response;
    }
658963
public function createFromApiProblem(
        ApiProblemInterface $apiProblem,
        string $accept,
        NormalizerContextInterface $context = null
    ): ResponseInterface {
        $status = $apiProblem->getStatus();

        $response = $this->responseFactory->createResponse($status)
            ->withHeader('Content-Type', str_replace('/', '/problem+', $accept));

        foreach ($apiProblem->getHeaders() as $name => $value) {
            $response = $response->withHeader($name, $value);
        }

        $body = $this->serializer->serialize($apiProblem, $accept, $context);

        $response->getBody()->write($body);

        return $response;
    }
1102182
public static function buildFromPsrResponse(ResponseInterface $response)
    {
        return new static(
            $response->getStatusCode(),
            $response->getHeaders(),
            $response->getBody(),
            $response->getProtocolVersion(),
            $response->getReasonPhrase()
        );
    }
52957
public function handleNotAllowed(ServerRequestInterface $request, ResponseInterface $response, array $methods)
    {
        $status = ($request->getMethod() === 'OPTIONS') ? 200 : 405;

        $detail = "Allowed methods: " . implode(', ', $methods);
        $extensions = [
            'allowed_methods' => $methods,
        ];

        $problem = new HTTPProblem($status, $detail, $extensions);
        return $this->renderProblem($response, $this->renderer, $problem);
    }
393440
protected function methodNotAllowed(string $message = "Method not allowed."): Response
    {
        return $this->getResponse()
            ->setContent($message)
            ->setStatusCode(Response::HTTP_METHOD_NOT_ALLOWED);
    }
624894
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        $input = $this->input($request);

        $payload = $this->domain->payload($input);

        return $this->responder->response($request, $payload);
    }
58254
public function getResponse(): ResponseInterface
    {
        if (is_null($this->response)) {
            if (method_exists($this, 'resolve')) {
                $this->setResponse($this->resolve(Response::class)->load());
            } else {
                $response = new Response();
                $this->setResponse($response->load());
            }
        }

        return $this->response;
    }
240190
public function withError(string $error): PayloadInterface
    {
        if ($this->error === $error) {
            return $this;
        }

        $clone = clone $this;
        $clone->error = $error;

        return $clone;
    }
1210033
public function process(
        ServerRequestInterface $request,
        RequestHandlerInterface $handler
    ): ResponseInterface {

        $clacker = 'GNU ' . $this->name;
        if ($request->hasHeader('X-Clacks-Overhead')) {
            $clacker = $request->getHeader('X-Clacks-Overhead')[0];
        }

        $response = $handler->handle($request);

        return $response->withHeader('X-Clacks-Overhead', $clacker);
    }
788909
private function getMessage($error, ServerRequestInterface $request, ResponseInterface $response)
    {
        if ($error instanceof ApiException) {
            $message = $error->getArrayMessage();
            return !empty($message) ? $message : $error->getMessage();
        }

        if ($error instanceof \Throwable) {
            return $error;
        }

        return 'An error ocurred.';
    }
875306
public function createResponse($exception)
    {
        if (!$exception instanceof FlattenException) {
            $exception = FlattenException::create($exception);
        }

        return new Response($this->decorate($this->getContent($exception, $this->showAllExceptions), $this->getStylesheet($exception)), $exception->getStatusCode(), $exception->getHeaders());
    }