定制 atournayre/exception-handler 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

atournayre/exception-handler

最新稳定版本:1.1.0

Composer 安装命令:

composer require atournayre/exception-handler

包简介

Centralized exception handling with Symfony and custom PHP attributes

README 文档

README

This component helps handle exceptions inside Symfony.

It is inspired from the article Centralized exception handling with Symfony and custom PHP attributes by Dejan Angelov. Read it before!

Install

Composer

composer require atournayre/exception-handler

Usage

  1. Define HttpStatusCodeExceptionHandler as a listener in your application.
  2. Declare attributes on your existing/new exceptions classes.
  3. Remove (or do not catch exception) in your controller.
  4. It works!

Define HttpStatusCodeExceptionHandler as a listener in your application

# config/services.yaml
services:
  Atournayre\Component\ExceptionHandler\Handler\HttpStatusCodeExceptionHandler:
    tags:
      - { name: kernel.event_listener, event: kernel.exception }

Declare attributes on your existing/new exceptions classes.

// Example for a NotFound (404)
#[NotFound]
class OrderNotFound extends Exception
{
    public function __construct(OrderId $id)
    {
        parent::__construct(
            sprintf('The order "%s" could not be found.', (string) $id)
        );
    }
}
// Example for a UnprocessableEntity (422)
#[UnprocessableEntity]
class OrderAlreadyShipped extends Exception { ... }
// Example for a Forbidden (403)
#[Forbidden]
class CustomerMismatch extends Exception { ... }

Contributing

Of course, open source is fueled by everyone's ability to give just a little bit of their time for the greater good. If you'd like to see a feature or add some of your own happy words, awesome! Tou can request it - but creating a pull request is an even better way to get things done.

Either way, please feel comfortable submitting issues or pull requests: all contributions and questions are warmly appreciated :).

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固