本文整理汇总了PHP中Throwable::getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Throwable::getStatusCode方法的具体用法?PHP Throwable::getStatusCode怎么用?PHP Throwable::getStatusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Throwable
的用法示例。
在下文中一共展示了Throwable::getStatusCode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: error
/**
* Return an error into an HTTP or JSON data array.
*
* @param string $title
* @return array
*/
public function error($title = null)
{
if ($title == null) {
$title = $this->debug ? 'The application could not run because of the following error:' : 'A website error has occurred. Sorry for the temporary inconvenience.';
}
$type = $this->request->getHeader('Content-Type');
$mesg = $this->exception->getMessage();
$file = $this->exception->getFile();
$line = $this->exception->getLine();
$code = $this->exception->getCode();
$statusCode = method_exists($this->exception, 'getStatusCode') ? $this->exception->getStatusCode() : null;
// Check status code is null
if ($statusCode == null) {
$statusCode = $code >= 100 && $code <= 500 ? $code : 400;
}
$this->response->withStatus($statusCode);
// Check logger exist
if ($this->logger !== null) {
// Send error to log
$this->logger->addError($this->exception->getMessage());
}
$this->isJson = isset($type[0]) && $type[0] == 'application/json';
// Check content-type is application/json
if ($this->isJson) {
// Define content-type to json
$this->response->withHeader('Content-Type', 'application/json');
$error = ['status' => 'error', 'status_code' => $statusCode, 'error' => $title, 'details' => []];
// Check debug
if ($this->debug) {
$error['details'] = ['message' => $mesg, 'file' => $file, 'line' => $line, 'code' => $code];
}
return $error;
}
// Define content-type to html
$this->response->withHeader('Content-Type', 'text/html');
$message = sprintf('<span>%s</span>', htmlentities($mesg));
$error = ['type' => get_class($this->exception), $error['status_code'] = $statusCode, 'message' => $message];
// Check debug
if ($this->debug) {
$trace = $this->exception->getTraceAsString();
$trace = sprintf('<pre>%s</pre>', htmlentities($trace));
$error['file'] = $file;
$error['line'] = $line;
$error['code'] = $code;
$error['trace'] = $trace;
}
$error['debug'] = $this->debug;
$error['title'] = $title;
return $error;
}
示例2: handle
/**
* @param Throwable $exception
*/
public function handle(\Throwable $exception)
{
if ($exception instanceof HttpException) {
http_response_code($exception->getStatusCode());
}
if (false === $this->debug) {
return;
}
if (null !== $exception->getPrevious()) {
$exception = $exception->getPrevious();
}
$message = $exception->getMessage();
$trace = $exception->getTrace();
array_unshift($trace, array('function' => '', 'file' => $exception->getFile() != null ? $exception->getFile() : null, 'line' => $exception->getLine() != null ? $exception->getLine() : null, 'args' => array()));
$firstTrace = array_shift($trace);
$firstTrace['excerpt'] = $this->excerpt($firstTrace['file'], $firstTrace['line']);
array_unshift($trace, $firstTrace);
echo $this->templateEngine->render(__DIR__ . '/templates/exception.php', array('message' => $message, 'trace' => $trace));
}
示例3: prepareErrorResponse
/**
* Prepare a response in case an error occurred.
*
* @param \Throwable $exception
* @param Http\Response $response
* @return void
*/
protected function prepareErrorResponse($exception, Http\Response $response)
{
$pathPosition = strpos($exception->getFile(), 'Packages/');
$filePathAndName = $pathPosition !== false ? substr($exception->getFile(), $pathPosition) : $exception->getFile();
$exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
$content = PHP_EOL . 'Uncaught Exception in Flow ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL;
$content .= 'thrown in file ' . $filePathAndName . PHP_EOL;
$content .= 'in line ' . $exception->getLine() . PHP_EOL . PHP_EOL;
$content .= Debugger::getBacktraceCode($exception->getTrace(), false, true) . PHP_EOL;
if ($exception instanceof Exception) {
$statusCode = $exception->getStatusCode();
} else {
$statusCode = 500;
}
$response->setStatus($statusCode);
$response->setContent($content);
$response->setHeader('X-Flow-ExceptionCode', $exception->getCode());
$response->setHeader('X-Flow-ExceptionMessage', $exception->getMessage());
}
示例4: display
/**
* Display the given exception to the user.
*
* @param \Exception $exception
* @return \Symfony\Component\HttpFoundation\Response
*/
public function display(\Throwable $exception)
{
$status = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
$headers = $exception instanceof HttpExceptionInterface ? $exception->getHeaders() : array();
return new Response(file_get_contents(__DIR__ . '/resources/plain.html'), $status, $headers);
}
示例5: display
/**
* Display the given exception to the user.
*
* @param \Exception $exception
* @return \Symfony\Component\HttpFoundation\Response
*/
public function display(\Throwable $exception)
{
$status = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
$headers = $exception instanceof HttpExceptionInterface ? $exception->getHeaders() : array();
return new Response($this->whoops->handleException($exception), $status, $headers);
}
示例6: getStatusCode
/**
* @param \Exception
*
* @return Int
*/
function getStatusCode(\Throwable $e)
{
return $e instanceof HttpExceptionInterface ? $e->getStatusCode() : Response::HTTP_INTERNAL_SERVER_ERROR;
}