Get a custom response.

@param string $data
@param string $mime
@param int    $code

@return \Symfony\Component\HttpFoundation\Response
776872
protected function raw($data, $mime, $code = 200)
    {
        $this->response->setStatusCode($code);
        $this->response->headers->add(['Content-Type' => $mime]);
        $this->response->setContent($data);

        return $this->response;
    }
1201243
static function json( $data, $code = 200 ) {
        return (new Response())
            ->setCode($code)
            ->setContent(json_encode($data))
            ->setContentType('application/json');
    }
857234
protected function response($message, $code)
  {
    Rest::response()->json([
      'status' => $message,
      'code' => $code
    ], $code);

    cancel();
  }
1276835
public function api($data, $code = null, $meta = [])
    {
        $json = [
            config('http.body') => $data,
            config('http.meta') => $meta,
            config('http.status') => $this->parseStatus($code ?? $this->getStatusCode()),
        ];

        return $this->json($json, $code);
    }
85734
protected function createSimpleResponse($code = 500, $content = 'Unknown error')
    {
        $response = new Response;
        $response->setStatusCode($code)
            ->setContent($content);

        return $response;
    }
377674
public function getMessageByCode(& $code, array $data = null)
    {
        // If we do not use a reference, then that defeats the purpose of
        // making the $errorMap a static property.
        $map = &static::getErrorMap();

        // When you can't find the code, use a default one.
        if (!\array_key_exists($code, $map)) {
            $code = static::UNKNOWN;
        }

        if (\is_array($data) && count($data) > 0) {
            return \vsprintf($map[$code], $data);
        }

        return $map[$code];
    }
616564
public function setHttpResponseCode($code)
        {
            if (!is_int($code) || (100 > $code) || (599 < $code)) {
                throw new Exception('Invalid HTTP response code');
            }

            if ((300 <= $code) && (307 >= $code)) {
                $this->_isRedirect = true;
            } else {
                $this->_isRedirect = false;
            }

            $this->_httpResponseCode = $code;

            return $this;
        }
621387
protected function yamlResponse($data, $code)
    {
        $yaml = Yaml::dump($data);

        return new \Illuminate\Http\Response($yaml, $code, [
            'Content-Type' => 'text/x-yaml',
        ]);
    }
572861
public function api($code, $msg = '', $data = '', $header = [], $options = [])
    {
        $this->json([
            'code' => $code,
            'msg' => $msg,
            'data' => $data
        ], $header, $options);
    }
498390
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
  {
    $response = new Response($code);

    \logger()->debug('Created PSR-7 Response (Guzzle)');

    return $response;
  }
933659
private function createErrorResponse($code, $message = null, array $data = [])
    {
        if (!$message) {
            $messages = $this->handler->getErrors()->getErrors();
            $message = isset($messages[$code]) ? $messages[$code] : 'Error';
        }

        $json = [
            'jsonrpc' => self::JSON_RPC_VERSION,
            'error' => [
                'code' => $code,
                'message' => $message
            ],
            'id' => $this->requestId
        ];

        if ($data) {
            $json['error']['data'] = $data;
        }

        return new JsonResponse($json, 200);
    }
525238
protected function respond($data, $code, array $headers = [])
    {
        return new JsonResponse($data, $code, array_merge($this->defaultHeaders(), $headers));
    }
535897
public function code ( $code = NULL ) {
      if ( $code === NULL )
        return $this->code;
      if ( ResponseCode::find( $code ) === NULL )
        throw new \InvalidArgumentException( "Response: no code $code" );
      $this->code = intval( $code );
      return $this;
    }
740623
public function iGetAResponseWithAStatusCodeOf($code)
    {
        $actual = $this->getGuzzleResponse()->getStatusCode();

        if ($actual != $code) {
            throw new ClientErrorResponseException(
                'Actual status code ' . $actual . ' does not match expected ' .
                'status code ' . $code . ' with message: ' .
                $this->getGuzzleResponse()->getMessage()
            );
        }
    }
686461
public function output($code, $msg = null, $data = null, $extraData = [])
    {
        if (is_null($msg)) {
            $msg = '未知';
        }

        $return = [
            'success' => (boolean)$code,
            'msg' => $msg,
        ];
        if ($extraData) {
            $return = array_merge($return, $extraData);
        }
        if (!is_null($data)) {
            $return['data'] = $data;
        }

        return $this->responseJson($return);
    }
30699
protected function generateResponse(
        int $code,
        string $reasonPhrase = ""
    ): ResponseInterface{
        return $this->getResponseFactory()
            ->createResponse($code, $reasonPhrase)
        ;
    }
1183548
public function redirect($uri, int $code = 302): ResponseInterface
    {
        if (!is_string($uri) && !$uri instanceof UriInterface) {
            throw new ResponseException("Redirect allowed only for string or UriInterface uris");
        }

        return $this->responseFactory->createResponse($code)->withHeader("Location", (string)$uri);
    }