toResponse.

@param $response
@param int $statusCode
@return ResponseContract

@throws \Illuminate\Contracts\Container\BindingResolutionException
519793
protected function toResponse($response, int $statusCode = 200): ResponseContract
    {
        if ($response instanceof JsonResponse) {
            $data = $response->getData(true);
            $statusCode = $response->getStatusCode();
        } elseif ($response instanceof Arrayable || $response instanceof Model) {
            $data = $response->toArray();
        } elseif (is_array($response)) {
            $data = $response;
        } elseif ($response instanceof ArrayObject) {
            // @todo 待验证
            $data = (array) $response;
        } else {
            throw new DomainException('The response type error');
        }

        /* @var ResponseContract $response */
        $response = $this->app->make('response');
        $response->setStatusCode($statusCode);

        return $data ? $response->setData($data)->setPackData(
            $this->app->make('bridging.packer')->pack($data)
        ) : $response;
    }
1086011
public function respond($content, $status = 200)
    {
        $transformed = $this->transform($content);

        return $this->responseFactory->json($transformed, $status);
    }
1177001
public function toUrl($url, $statusCode = 302)
    {
        $server = $this->getServer();

        $response = $server->getResponse(false)
            ->withHeader('Location', $url)
            ->withStatus($statusCode);

        return $response;
    }
1093412
protected function createApiClientException(
        $statusCode,
        $message,
        $requestContents,
        $responseContents
    ): ApiClientException {
        return ExceptionFactory::create($statusCode, $message, $requestContents, $responseContents);
    }
261318
public function redirect($location, $statusCode = 302) {
        $this->response->setHeader('Location', $location, true, $statusCode);
        return $this;
    }
372774
public function respond($response, $status, $headers, $options)
    {
        switch ($this->getRequestFormat()) {
            case 'html' :
            case 'text/html' :
                return Response::make($response, $status, $headers, $options)
                    ->header('Content-Type', 'text/html');
            default :
                // whether 'Content-Type' is NULL or equal to anything such as 'application/json' response will be JSON
                return Response::json($response, $status, $headers, $options);
        }
    }
703163
public function respond(int $statusCode = null, array $headers = []):JsonResponse
    {
        if (! is_null($statusCode)) {
            $this->setStatus($statusCode);
        }

        $data = $this->toArray();
        $data = $this->includeStatusCode($data);
        $data = $this->includeSuccessFlag($data);

        return $this->responseFactory->json($data, $this->statusCode, $headers);
    }
512955
public function response($body, $headerArray = array(), $statusCode = 200, $reasonPhrase = null)
    {
        $headers = $this->builder->editableHeaders($headerArray);
        return $this->buildResponse($headers, $body, $statusCode, $reasonPhrase);
    }
626710
public function response($content, int $statusCode = 200, string $statusMessage = 'OK'): Response
    {
        $response = [
            'statusCode' => $statusCode,
            'statusMessage' => $statusMessage,
            'content' => $content,
        ];

        if ($this->config->application->debug->logRequest) {
            $this->log->addInfo('RESPONSE', $response);
        }

        // Create a response since it's an ajax
        //in order to use the current response instead of having to create a new object , this is needed for swoole servers
        $response = $this->response ?? new Response(); 
        $response->setStatusCode($statusCode, $statusMessage);
        $response->setContentType('application/vnd.api+json', 'UTF-8');
        $response->setJsonContent($content);

        return $response;
    }
1289552
public function success(int $statusCode, string $message, $data = null): JsonResponse
    {

        $this->setStatusCode($statusCode);

        $this->setMessage($message);

        $this->setData($data);


        $content['message'] = $this->getMessage();


        if (null !== $this->getCode()) {
            $content['code'] = $this->getCode();
        }


        $content['status_code'] = $this->getStatusCode();


        if (null !== $this->getData() && $this->getErrors() !== $this->getData()) {
            $content['data'] = $this->getData();
        }

        if (null !== $this->getErrors()) {
            $content['errors'] = $this->getErrors();
        }

        $content += $this->Hypermedia;

        return new JsonResponse($content, $this->getHttpStatusCode() ?: $this->getStatusCode());
    }
641100
protected function createResponse($statusCode, $contentType)
    {
        switch ($statusCode) {
            case 200:
            case 201:
                return $this->createContent($contentType);
            default:
                // fail on error
                if ($this->curlOptions[45]) {
                    throw new LushRequestException($this, ['message' => sprintf('%d - Mocked server error', $statusCode), 'code' => $statusCode, 'response' => 'false']);
                }

                return json_encode(['url' => $this->ch, 'status' => sprintf('Error: %d', $statusCode)]);
        }
    }
479111
public function setStatus(int $statusCode):ResponseBuilder
    {
        if ($statusCode < 400 || $statusCode >= 600) {
            throw new InvalidArgumentException("{$statusCode} is not a valid error HTTP status code.");
        }
        return parent::setStatus($statusCode);
    }
127709
public function respond($statusCode = 200, $headers = [], $options = 0)
    {
        $response = new JsonResponse();

        $response->setData($this->createData()->toArray());

        if (is_int($statusCode)) {
            $statusCode = function (JsonResponse $response) use ($statusCode) {
                return $response->setStatusCode($statusCode);
            };
        }

        if (is_array($headers)) {
            $headers = function (JsonResponse $response) use ($headers) {
                return $response->withHeaders($headers);
            };
        }

        if (is_int($options)) {
            $options = function (JsonResponse $response) use ($options) {
                $response->setEncodingOptions($options);

                return $response;
            };
        }

        if (is_callable($options)) {
            $options($response);
        }

        if (is_callable($statusCode)) {
            $statusCode($response);
        }

        if (is_callable($headers)) {
            $headers($response);
        }

        return $response;
    }
206554
public static function create(
        int $statusCode,
        string $message,
        string $request,
        string $response
    ): ApiClientException {
        switch ($statusCode) {
            case 400:
                $exception = new BadRequestException($message, $request, $response);
                break;
            case 401:
                $exception = new UnauthorizedException($message, $request, $response);
                break;
            case 403:
                $exception = new ForbiddenException($message, $request, $response);
                break;
            case 404:
                $exception = new NotFoundException($message, $request, $response);
                break;
            default:
                $exception = new ApiClientException($message, $statusCode, $request, $response);
                break;
        }
        return $exception;
    }
851337
public function setHeaderResponse($statusCode, $message = '')
    {
        $this->statusCode = $statusCode;
        $this->message = $message;
        if ($message == '') {
            $this->message = self::$defaultMessages[$statusCode];
        }

        if (empty($this->message)) {
            throw new RestException('Invalid http response status code: ' . $statusCode);
        }

        return $this;
    }
1358633
public function setStatus($statusCode)
    {
        if ($this->statusCode === null) {
            $this->statusCode = $statusCode;
            $this->response->setStatusCode($statusCode);
        }
    }
670841
public function error($errorCode = null, int $statusCode = null, $message = null):JsonResponse
    {
        if ($exception = config("responder.exceptions.$errorCode")) {
            if (class_exists($exception)) {
                throw new $exception();
            }
        }

        return $this->errorResponse->setError($errorCode, $message)->respond($statusCode);
    }