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


PHP Exception::getHttpCode方法代码示例

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


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

示例1: handleException

 /**
  * Exeptions are returned to client in the form
  * of a message in the 'error' element
  * Appropriate http response code is used
  *
  * @param \Exception $e
  */
 protected function handleException(\Exception $e)
 {
     if (!$this->restful) {
         throw $e;
     }
     if ($e instanceof \Lampcms\HttpResponseCodeException) {
         $code = $e->getHttpCode();
         $this->Registry->Response->setHttpCode($code);
         /**
          * @todo if $code = 405 and bRequirePost then
          * set extra header Allow: POST
          * This is to comply with RFC
          */
     } else {
         $this->Registry->Response->setHttpCode(500);
     }
     $err = \strip_tags($e->getMessage());
     $err2 = 'API Exception caught in: ' . $e->getFile() . ' on line: ' . $e->getLine() . ' error: ' . $err;
     d($err2);
     $this->Output->setData(array('error' => $err));
     $this->Registry->Response->setBody($this->Output);
 }
开发者ID:netconstructor,项目名称:LampCMS,代码行数:29,代码来源:Api.php

示例2: handleException

 /**
  * {@inheritDoc}
  */
 public function handleException(\Exception $e)
 {
     $refl = new \ReflectionClass($e);
     if ($e instanceof HttpExceptionInterface) {
         $title = sprintf('%s::%s', $refl->getShortName(), $e->getErrorType());
         $detail = $e->getMessage();
         $status = $e->getHttpCode();
     } else {
         $title = $refl->getShortName();
         $detail = 'Oh no! Something bad happened on the server! Please try again.';
         $status = 500;
     }
     $serialized = $this->getSerializer()->serializeError($title, $detail, $status);
     $payload = new Rest\RestPayload($serialized);
     return $this->createRestResponse($status, $payload);
 }
开发者ID:as3io,项目名称:modlr,代码行数:19,代码来源:AbstractAdapter.php

示例3: handleException

 /**
  * handles an exception when loading a page
  *
  * @param Exception $e
  * @param string $controller name of controller
  * @param string $action name of action
  * @return void
  */
 public function handleException(\Exception $e, $controller = null, $action = null)
 {
     if ($this->_delegate) {
         $this->_delegate->appCaughtException($e, $controller, $action);
     }
     // turn other exceptions into sonic exceptions
     if (!$e instanceof Exception) {
         $e = new Exception($e->getMessage(), Exception::INTERNAL_SERVER_ERROR, $e);
     }
     // only set the http code if output hasn't started
     if (!headers_sent()) {
         header($e->getHttpCode());
     }
     $json = false;
     $id = null;
     // in turbo mode we have to write the exception markup out to the
     // same div created before the exception was triggered.  this means
     // we have to get the id based on the controller and action that the
     // exception came from
     if ($this->getSetting(self::TURBO) && $this->_layout_processed) {
         $json = true;
         $id = View::generateId($controller, $action);
     }
     $completed = false;
     // controller and action are only null if this is a page not found
     // because we were not able to match any routes.  in all other cases
     // we can get the initial controller and action to determine if it has
     // completed
     if ($controller !== null && $action !== null) {
         $req = $this->getRequest();
         $first_controller = $req->getControllerName();
         $first_action = $req->getAction();
         $completed = $this->getController($first_controller)->hasCompleted($first_action);
     }
     $args = array('exception' => $e, 'top_level_exception' => !$completed, 'from_controller' => $controller, 'from_action' => $action);
     return $this->_runController('main', 'error', $args, $json, $id);
 }
开发者ID:NePTeR,项目名称:sonic,代码行数:45,代码来源:App.php

示例4: handleException

 public function handleException(\Exception $e, $controller = null, $action = null)
 {
     if ($this->_delegate) {
         $this->_delegate->appCaughtException($e, $controller, $action);
     }
     if (!$e instanceof Exception) {
         $e = new Exception($e->getMessage(), Exception::INTERNAL_SERVER_ERROR, $e);
     }
     if (!headers_sent()) {
         header($e->getHttpCode());
     }
     $json = false;
     $id = null;
     if ($this->getSetting(self::TURBO) && $this->_layout_processed) {
         $json = true;
         $id = View::generateId($controller, $action);
     }
     $completed = false;
     if ($controller !== null && $action !== null) {
         $req = $this->getRequest();
         $first_controller = $req->getControllerName();
         $first_action = $req->getAction();
         $completed = $this->getController($first_controller)->hasCompleted($first_action);
     }
     $args = array('exception' => $e, 'top_level_exception' => !$completed, 'from_controller' => $controller, 'from_action' => $action);
     return $this->_runController('main', 'error', $args, $json, $id);
 }
开发者ID:NePTeR,项目名称:sonic,代码行数:27,代码来源:Core.php


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