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


PHP Exception::getAllowedMethods方法代码示例

本文整理汇总了PHP中Exception::getAllowedMethods方法的典型用法代码示例。如果您正苦于以下问题:PHP Exception::getAllowedMethods方法的具体用法?PHP Exception::getAllowedMethods怎么用?PHP Exception::getAllowedMethods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Exception的用法示例。


在下文中一共展示了Exception::getAllowedMethods方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process

 public static function process(\Exception $e, Request $request, Response $response)
 {
     if ($e instanceof BaseException) {
         $response->withStatus($e->getHttpStatus());
         $response->write(Code::json($e->getCode(), $e->getMessage()));
     } else {
         if ($e instanceof MethodNotAllowedException) {
             $response->withStatus(405);
             $allow = implode(', ', $e->getAllowedMethods());
             $response->withHeader('Allow', $allow);
             $response->write(Code::json(Code::METHOD_NOT_ALLOWED, 'allow: ' . $allow));
         } else {
             if ($e instanceof NotFoundException) {
                 $response->withStatus(404);
                 $response->write(Code::json(Code::RESOURCE_NOT_FOUND));
             } else {
                 if ($e instanceof UnsupportedMediaType) {
                     $response->withStatus(415);
                     $response->write(Code::json(Code::UNSUPPORTED_MEDIA_TYPE, $e->getMessage()));
                 } else {
                     if ($e instanceof BadBodyException) {
                         $response->withStatus(400);
                         $response->write(Code::json(Code::BAD_BODY, $e->getMessage()));
                     } else {
                         if ($e instanceof \PDOException) {
                             $response->withStatus(502);
                             $response->write(Code::json(Code::DATABASE_ERROR));
                             trigger_error(Str::exceptionToString($e), E_USER_WARNING);
                         } else {
                             if ($e instanceof \RedisException) {
                                 $response->withStatus(502);
                                 $response->write(Code::json(Code::CACHE_ERROR));
                                 trigger_error(Str::exceptionToString($e), E_USER_WARNING);
                             } else {
                                 $response->withStatus(500);
                                 $response->write(Code::json(Code::INTERNAL_SERVER_ERROR));
                                 trigger_error(Str::exceptionToString($e), E_USER_WARNING);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:raframework,项目名称:ra,代码行数:45,代码来源:ExceptionHandler.php

示例2: sysHandleException

 private function sysHandleException(\Exception $e)
 {
     if ($e instanceof MethodNotAllowedException) {
         $this->response->withStatus(405);
         $this->response->withHeader('Allow', implode(', ', $e->getAllowedMethods()));
     } else {
         if ($e instanceof NotFoundException) {
             $this->response->withStatus(404);
         } else {
             $this->response->withStatus(500);
             trigger_error('Unhandled exception \'' . get_class($e) . '\' with message \'' . $e->getMessage() . '\'' . ' in ' . $e->getFile() . ':' . $e->getLine() . "\nStack trace:\n" . $e->getTraceAsString(), E_USER_WARNING);
         }
     }
 }
开发者ID:raframework,项目名称:ra,代码行数:14,代码来源:App.php

示例3: handleRoutingException

 /**
  * Convert routing exception to HttpKernel version.
  *
  * @param  Exception  $e
  * @return void
  */
 protected function handleRoutingException(\Exception $e)
 {
     if ($e instanceof ResourceNotFoundException) {
         throw new NotFoundHttpException($e->getMessage());
     } elseif ($e instanceof MethodNotAllowedException) {
         $allowed = $e->getAllowedMethods();
         throw new MethodNotAllowedHttpException($allowed, $e->getMessage());
     }
 }
开发者ID:centaurustech,项目名称:sagip,代码行数:15,代码来源:Router.php


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