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


PHP Exception::toArray方法代码示例

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


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

示例1: toArray

 /**
  * @return array
  */
 public function toArray()
 {
     $return = [];
     if ($this->getReturnStatusCode()) {
         $return['statusCode'] = $this->getStatusCode();
     }
     if (isset($this->exception)) {
         if ($this->exception instanceof FormValidationException) {
             $error = $this->exception->toArray();
         } elseif ($this->exception instanceof HttpException) {
             $error = ['code' => self::ERROR_HTTP_PREFIX . StringUtil::classToSnakeCase($this->exception, 'HttpException'), 'message' => $this->exception->getMessage()];
         } else {
             $error = ['code' => trim(self::ERROR_GENERAL_PREFIX . StringUtil::classToSnakeCase($this->exception, 'Exception'), '.'), 'message' => $this->exception->getMessage()];
         }
         $return['error'] = $error;
     }
     if (isset($this->data)) {
         $return['data'] = $this->data;
     }
     if (isset($this->location)) {
         $return['location'] = $this->location;
     }
     if (isset($this->pagination)) {
         $return['pagination'] = $this->pagination;
     }
     return $return;
 }
开发者ID:EdgarPost,项目名称:symfony-rest-api-bundle,代码行数:30,代码来源:ResponseContainer.php

示例2: exceptionToArray

 /**
  * @return array
  */
 protected function exceptionToArray()
 {
     if ($this->exception instanceof ExceptionInterface) {
         $error = $this->exception->toArray();
     } elseif ($this->exception instanceof HttpException) {
         $error = $this->httpExceptionToArray();
     } else {
         $error = $this->generalExceptionToArray();
     }
     if ($this->isReturnStackTrace()) {
         $error['stack_trace'] = $this->getExceptionStackTrace();
     }
     return $error;
 }
开发者ID:mediamonks,项目名称:symfony-rest-api-bundle,代码行数:17,代码来源:ResponseModel.php

示例3: formatResponse

 /**
  * Formats and returns
  * @param null $result
  * @param \JsonRpc2\Exception|null $error
  * @param null $id
  * @return array
  */
 public static function formatResponse($result = null, Exception $error = null, $id = null)
 {
     $resultKey = 'result';
     if (!empty($error)) {
         $resultKey = 'error';
         $resultValue = $error->toArray();
     } else {
         if (null === $result) {
             $resultValue = self::$defaultResult;
         } else {
             $resultValue = $result;
         }
     }
     return ['jsonrpc' => '2.0', $resultKey => $resultValue, 'id' => $id];
 }
开发者ID:wowkaster,项目名称:yii2-json-rpc-2.0,代码行数:22,代码来源:Helper.php

示例4: exception_as_array

/**
 * Convert given exception to an array of scalar values.
 *
 * @param \Exception $e_
 * @param bool $includeStackTrace_
 * @param bool $stackTraceAsArray_
 *
 * @return scalar[][]
 */
function exception_as_array(\Exception $e_, $includeStackTrace_ = false, $stackTraceAsArray_ = false)
{
    if ($e_ instanceof \Components\Runtime_Exception_Transformable) {
        return $e_->toArray($includeStackTrace_, $stackTraceAsArray_);
    }
    $type = Components\Type::of($e_);
    $exceptionAsArray = ['id' => \math\hasho_md5($e_), 'type' => $type->name(), 'code' => $e_->getCode(), 'namespace' => $type->ns()->name(), 'message' => $e_->getMessage(), 'file' => $e_->getFile(), 'line' => $e_->getLine()];
    if ($includeStackTrace_ && $stackTraceAsArray_) {
        $exceptionAsArray['stack'] = exception_stacktrace_as_array($e_);
    } else {
        if ($includeStackTrace_) {
            $exceptionAsArray['stack'] = $e_->getTraceAsString();
        }
    }
    return $exceptionAsArray;
}
开发者ID:evalcodenet,项目名称:net.evalcode.components.runtime,代码行数:25,代码来源:util.php


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