本文整理汇总了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;
}
示例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;
}
示例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];
}
示例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;
}