internations/exception-bundle
Composer 安装命令:
composer require internations/exception-bundle
包简介
Helps making your Symfony Bundle a good Exception citizen. Yes, it’s opinionated.
README 文档
README
Clean exception handling for your Symfony 2 bundles
ExceptionBundle helps you managing the exceptions of your bundle:
- Generate exception subclasses from command line including a marker interface
- Replace all global throw statements in a bundle with bundle specific exception classes
Why should you care?
- The simpler exceptions are distinguishable by type, the simpler exceptional conditions are handled
- Providing a marker interface all bundle exception classes implement allows clients to dramatically simplify exception handling
- Usually, creating all the exception sub classes by hand is cumbersome,
ExceptionBundlecan help you
Usage
Generate bundle specific exception subclasses
This command will generate a bunch of exceptions
php app/console exception:generate app/src/MyVendor/MyBundle "MyVendor\MyBundle" ExceptionInterface RuntimeException DomainException
ls app/src/MyVendor/MyBundle/Exception
ExceptionInterface.php RuntimeException.php DomainException.php
cat app/src/MyVendor/MyBundle/Exception/RuntimeException.php
<?php namespace MyVendor\MyBundle\Exception; use RuntimeException as BaseRuntimeException; class RuntimeException extends BaseRuntimeException implements ExceptionInterface { }
You can also specify the shortcut "spl" to subclass all Spl Exceptions
Rewrite bundle exceptions
ExceptionBundle uses PHP Parser to rewrite all throw statements in a bundle code base.
cat app/src/MyVendor/MyBundle/MyClass.php
<?php namespace MyVendor\MyBundle; use RuntimeException; ... throw new RuntimeException('Runtime error'); ... throw new \InvalidArgumentException('Invalid argument');
php app/console exception:rewrite app/src/MyVendor/MyBundle "MyVendor\MyBundle"
Rewrites the code to:
<?php namespace MyVendor\MyBundle; use MyVendor\MyBundle\Exception\InvalidArgumentException; use MyVendor\MyBundle\Exception\RuntimeException; ... throw new RuntimeException('Runtime error'); ... throw new InvalidArgumentException('Invalid argument'); ...
Installation
Add internations/exception-bundle to your composer.json and edit AppKernel.php like this:
<?php ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( ... ); if ($this->debug) { $bundles[] = new InterNations\Bundle\ExceptionBundle\InterNationsExceptionBundle(); } } }
internations/exception-bundle 适用场景与选型建议
internations/exception-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 48.06k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2012 年 12 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 internations/exception-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 internations/exception-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 48.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 21
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-12-18