Create a new response.

@param      integer            $code   HTTP status code

@return     ResponseInterface
498390
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
  {
    $response = new Response($code);

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

    return $response;
  }
476609
public static function create(int $code = 500, array $context = [], Throwable $previous = null): self
    {
        if (!isset(self::$phrases[$code])) {
            throw new RuntimeException("Http error not valid ({$code})");
        }

        $exception = new static(self::$phrases[$code], $code, $previous);
        $exception->setContext($context);

        return $exception;
    }
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);
    }
4231
protected function createDefaultErrorResponse(int $code): \Generator
    {
        $sink = new MemorySink(sprintf('%d Error', $code));

        $headers = [
            'Connection' => 'close',
            'Content-Type' => 'text/plain',
            'Content-Length' => $sink->getLength(),
        ];

        return new BasicResponse($code, $headers, $sink);
        yield; // Unreachable, but makes method a coroutine.
    }
268412
public function withStatusCode(int $code)
    {
        if ($this->statusCode == $code) {
            return $this;
        }

        $that = clone($this);
        $that->statusCode = $code;
        return $that;
    }
1093908
public function createResponse(array $responseData, $code = 200)
    {
        $responseType = '.json';
        
        $route = Request::route();
        
        $responseType = $route ? $route->parameter('type', $responseType) : $responseType;

        switch ($responseType) {
            case '.yaml':
                return $this->yamlResponse($responseData, $code);
            case '.xml':
                return $this->xmlResponse($responseData, $code);
            default:
                return $this->jsonResponse($responseData, $code);
        }
    }
11439
public function setCode( $code = null)
	{
		// Require that the response be unlocked before changing it
		$this->requireUnlocked();
		$this->status = new Status($code);
		return $this;
	}
1201243
static function json( $data, $code = 200 ) {
        return (new Response())
            ->setCode($code)
            ->setContent(json_encode($data))
            ->setContentType('application/json');
    }
1342356
public static function createResponse($body, $mediaType = 'text/html', $code = 200)
    {
        return Factory::createResponse()
            ->withStatus($code)
            ->withHeader('Content-Type', $mediaType)
            ->withBody(Factory::createStream($body));
    }
621387
protected function yamlResponse($data, $code)
    {
        $yaml = Yaml::dump($data);

        return new \Illuminate\Http\Response($yaml, $code, [
            'Content-Type' => 'text/x-yaml',
        ]);
    }
283901
public function code(int $code = 200) : Rest
  {
    $this->code = $code;
    header('HTTP/1.1 '.$this->code);
    return $this;
  }
708073
public static function errorToException($code){
    if(!isset(self::$codeMap[$code])){
      return new BadResponseException(sprintf(
        'Undefined error code "%s"',
        $code
      ));
    }
    $exceptionClass = self::$codeMap[$code];
    return  new $exceptionClass;
  }
635310
public function show($code)
    {
        $lang = $this->langRepo->getByCode($code);
        if (empty($lang)) {
            return $this->respondNotFound();
        }
        return $this->respondWithSuccess($lang, new LangTransformer);
    }
620167
public function postSignup($code = null)
    {
        if ($code === null) {
            throw new NotFoundHttpException();
        }

        $invite = Invite::where('code', '=', $code)->first();

        if (!$invite || $invite->is_claimed) {
            throw new BadRequestHttpException();
        }

        try {
            execute(new SignupUserCommand(
                Binput::get('username'),
                Binput::get('password'),
                Binput::get('email'),
                User::LEVEL_USER
            ));
        } catch (ValidationException $e) {
            return cachet_redirect('signup.invite', [$invite->code])
                ->withInput(Binput::except('password'))
                ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('cachet.signup.failure')))
                ->withErrors($e->getMessageBag());
        }

        execute(new ClaimInviteCommand($invite));

        return cachet_redirect('status-page')
            ->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.signup.success')));
    }
104421
protected function createErrorResponse($content = 'Unknown Error', $code = 500)
    {
        $data = [
            'message' => $content
        ];

        $response = $this->createJsonResponse($data, $code);
        return $response;
    }
700838
public static function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
    {
        return self::getResponseFactory()->createResponse($code, $reasonPhrase);
    }
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);
    }