本文整理汇总了PHP中Illuminate\Http\Response::getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getStatusCode方法的具体用法?PHP Response::getStatusCode怎么用?PHP Response::getStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Response
的用法示例。
在下文中一共展示了Response::getStatusCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: serialize
/**
* Serialize a response.
*
* @param \Illuminate\Http\Response $response
*
* @return string
*/
public function serialize(Response $response)
{
$content = $response->getContent();
$statusCode = $response->getStatusCode();
$headers = $response->headers;
return serialize(compact('content', 'statusCode', 'headers'));
}
示例2: render
/**
* Render an exception into a response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function render($request, Exception $exception)
{
$response = (new SymfonyExceptionHandler(env('APP_DEBUG', false)))->createResponse($exception);
$response = new Response($response->getContent(), $response->getStatusCode(), $response->headers->all());
$response->exception = $exception;
return $response;
}
示例3: makeMessageFromResponse
protected function makeMessageFromResponse(Response $response)
{
$message['original_content'] = $response->getOriginalContent();
$message['content'] = $response->getContent();
$message['status_code'] = $response->getStatusCode();
return json_encode($message, JSON_PRETTY_PRINT);
}
示例4: makeFromExisting
/**
* Make an API response from an existing response object.
*
* @author Morten Rugaard <moru@nodes.dk>
*
* @param \Illuminate\Http\Response $old
* @return \Nodes\Api\Http\Response
*/
public static function makeFromExisting(IlluminateResponse $old)
{
// Support for custom status code and message
$statusCode = $old instanceof self ? $old->getStatusCodeAndMessage() : $old->getStatusCode();
// Generate API response from response object
$new = static::create($old->getOriginalContent(), $statusCode);
$new->headers = $old->headers;
return $new;
}
示例5: assertPageLoaded
/**
* Assert that a given page successfully loaded.
*
* @param string $uri
* @param string|null $message
*
*/
protected function assertPageLoaded($uri, $message = null)
{
$status = $this->response->getStatusCode();
try {
$this->assertEquals(200, $status);
} catch (PHPUnitException $e) {
$message = $message ?: "A request to [{$uri}] failed. Received status code [{$status}].";
throw new HttpException($message, null, $this->response->exception);
}
}
示例6: filter
/**
* Allow Lassy to save only valid html responses
*
* @param \Illuminate\Http\Response $response
* @return boolean
*/
public function filter(Response $response)
{
if (200 !== $response->getStatusCode()) {
return false;
}
if (false === strpos($response->headers->get('Content-Type'), 'text/html')) {
return false;
}
return true;
}
示例7: renderPretty
/**
* Return an ajax or prettify with whoops.
*
* @param Exception $e
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Response $response
*
* @return mixed
*/
public function renderPretty(Exception $e, $request, $response)
{
if ($this->areYouAnAjax($request)) {
$res = [];
$res['status'] = 'error';
$res['message'] = empty($e->getMessage()) ? $response::$statusTexts[$response->getStatusCode()] : $e->getMessage();
$res['file'] = $e->getFile();
$res['line'] = $e->getLine();
$res['statusCode'] = $response->getStatusCode();
$res['statusText'] = $response::$statusTexts[$response->getStatusCode()];
$res['error'] = $res;
return $response->setContent($res);
} else {
if (view()->exists('errors.' . $response->getStatusCode())) {
return response()->view('errors.' . $response->getStatusCode(), compact('response'));
}
$whoops = (new Run())->pushHandler(new PrettyPageHandler());
return $whoops->handleException($e);
}
}
示例8: after
/**
* Module after response hook.
*
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Http\Response $response
*
* @return void
*/
public function after(Application $app, $response)
{
$this->data['id'] = $app->make(Agent::class)->getKey();
$this->data['versions']['php'] = phpversion();
$this->data['versions']['laravel'] = Application::VERSION;
$this->data['environment'] = $app->config->get('app.env');
$this->data['http']['path'] = $app->request->path();
$this->data['http']['method'] = $app->request->method();
$this->data['http']['status'] = $response->getStatusCode();
$this->data['time']['start'] = LARAVEL_START;
$this->data['time']['end'] = microtime(true);
$this->data['time']['total'] = microtime(true) - LARAVEL_START;
$this->data['memory'] = memory_get_peak_usage();
}
示例9: setResponse
/**
* @param Response $response
*/
public function setResponse(Response $response)
{
$this->response = $response;
$statusCode = $this->response->getStatusCode();
if ($statusCode >= 300 && $this->debug_mode) {
echo "\nResponse STATUS CODE is {$statusCode}:\n";
$responseData = $this->getResponseData();
if ($responseData) {
$this->printArray($responseData);
} else {
$this->printLine($this->getResponse());
}
}
}
示例10: assertResponseStatus
/**
* Assert that the client response has a given code.
*
* @param int $code
* @return $this
*/
public function assertResponseStatus($code)
{
$actual = $this->response->getStatusCode();
PHPUnit::assertEquals($code, $this->response->getStatusCode(), "Expected status code {$code}, got {$actual}.");
return $this;
}
示例11: seeStatusCode
/**
* Asserts that the status code of the response matches the given code.
*
* @param int $status
* @return $this
*/
protected function seeStatusCode($status)
{
$this->assertEquals($status, $this->response->getStatusCode());
return $this;
}
示例12: __construct
/**
* Create a new internal HTTP exception instance.
*
* @param \Illuminate\Http\Response $response
* @param string $message
* @param \Exception $previous
* @param array $headers
* @param int $code
*
* @return void
*/
public function __construct(Response $response, $message = null, Exception $previous = null, array $headers = [], $code = 0)
{
$this->response = $response;
parent::__construct($response->getStatusCode(), $message, $previous, $headers, $code);
}
示例13: toIlluminateResponse
/**
* Map exception into an illuminate response.
*
* @param \Symfony\Component\HttpFoundation\Response $response
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
protected function toIlluminateResponse($response, Exception $e)
{
$response = new Response($response->getContent(), $response->getStatusCode(), $response->headers->all());
$response->exception = $e;
return $response;
}
示例14: makeFromExisting
/**
* Make an API response from an existing Illuminate response.
*
* @param \Illuminate\Http\Response $old
*
* @return \Dingo\Api\Http\Response
*/
public static function makeFromExisting(IlluminateResponse $old)
{
$new = static::create($old->getOriginalContent(), $old->getStatusCode());
$new->headers = $old->headers;
return $new;
}
示例15: shouldCache
/**
* Determines whether the given request/response should be cached.
*
* @param \Illuminate\Http\Response $response
* @return bool
*/
protected function shouldCache($request, $response)
{
return $request->isMethod('GET') && $response->getStatusCode() == 200;
}