承接 aivo/exceptions 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aivo/exceptions

最新稳定版本:1.0.0

Composer 安装命令:

composer require aivo/exceptions

包简介

Exceptions

README 文档

README

BaseException is an abstract class.

Installation

Run

composer require aivo/exceptions

Or edit composer.json and add

    "require": {
        "aivo/exceptions": "^1"
    }

Function Declaration

\Aivo\BaseException::__construct ([\Psr\Log\LoggerInterface $logger = null, $previous = null, $previousLevel = null])

####\Psr\Log\LoggerInterface $logger A PSR-3 compatible object. If provided, it will call the logger's method matching the error level when the exception is . It's possible to add a logger after the object has been instantiated using $\Aivo\BaseException->setLogger(\Psr\Log\LoggerInterface $logger) and $\Aivo\BaseException->log().

####\Exception $previous It is impossible to add a previous exception runtime so it has to be added while creating a new BaseException object.

####string $previousLevel If provided, it will log the previous exception provided using this level. This is useful for logging exceptions that do not extend \Aivo\BaseException, such as PDOException.

Extending the object

It is suggested that you create a new class for every message and code you need to send. Each code should also be unique, ideally on a global scope. This is because the error messages could change at any time so applications should not depend on the actual description text.

Catching the object

public function responseException(\Exception $exception, Response $response)
{
    if ($exception instanceof \Aivo\BaseException) {
        $data = $exception->__toArray();
        $httpCode = $exception->getHttpCode();

    } else {
        $data = [
            'class' => get_class($exception),
            'error' => $exception->getCode(),
            'message' => $exception->getMessage(),
        ];
        $httpCode = 409;
    }

    return $response->withJson($data)
                    ->withStatus($httpCode);
}

Logging the previous exception

To log a previous exception (provided in the constructor), simply add a third parameter with the desired level. Level has to be PSR-3 compliant. Example:

try {
    throw new \Exception('Super secreta');
}
catch (\Exception $e) {
    throw new \Aivo\Exceptions\Word\NotFound(
        $this->logger(),
        $e,
        \Aivo\BaseException::ERROR
    );
}

Author

Matias Pino - mpino@aivo.co

This project uses Semantic Versioning 2.0.0

统计信息

  • 总下载量: 30.29k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: propietary
  • 更新时间: 2016-10-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固