当前位置: 首页>>代码示例>>PHP>>正文


PHP Throwable::getStatusCode方法代码示例

本文整理汇总了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;
 }
开发者ID:aracaw,项目名称:wiring,代码行数:56,代码来源:ErrorHandler.php

示例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));
 }
开发者ID:PierreCharles,项目名称:uFramework-PHP,代码行数:22,代码来源:ExceptionHandler.php

示例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());
 }
开发者ID:vjanoch,项目名称:flow-development-collection,代码行数:26,代码来源:InternalRequestEngine.php

示例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);
 }
开发者ID:jadz,项目名称:laravel-framework-4.2.18-php7,代码行数:12,代码来源:PlainDisplayer.php

示例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);
 }
开发者ID:jadz,项目名称:laravel-framework-4.2.18-php7,代码行数:12,代码来源:WhoopsDisplayer.php

示例6: getStatusCode

/**
 * @param \Exception
 *
 * @return Int
 */
function getStatusCode(\Throwable $e)
{
    return $e instanceof HttpExceptionInterface ? $e->getStatusCode() : Response::HTTP_INTERNAL_SERVER_ERROR;
}
开发者ID:plispe,项目名称:kiss,代码行数:9,代码来源:functions.php


注:本文中的Throwable::getStatusCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。