mabs/exceptionizer-bundle
Composer 安装命令:
composer require mabs/exceptionizer-bundle
包简介
This bundle provides a simple way to play with php Exceptions.
README 文档
README
Play with Exceptions :D This bundle help to get a low coupling between exception class object in your code
Installation
Exceptionizer uses Composer, please checkout the composer website for more information.
The simple following command will install exceptionizer-bundle into your project. It also add a new
entry in your composer.json and update the composer.lock as well.
$ composer require 'mabs/exceptionizer-bundle'
Then, you can enable it in your kernel:
// app/AppKernel.php public function registerBundles() { $bundles = array( ... new Mabs\ExceptionizerBundle\MabsExceptionizerBundle(), ...
Usage
Now you can use Exceptionizer service to throw Exceptions:
$this->container->get('exceptionizer') ->throwException('\\Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException', array('Your message'));
OR define your Exception in your config.yml file like this :
mabs_exceptionizer: exceptions: bar_code_exception: class: Mabs\BarCodeBundle\Exception\BarCodeException arguments: # optional message: "bar code exception" # optional code: 0 # optional
and pass the config key to the service:
$this->container->get('exceptionizer')->throwException('bar_code_exception');
Events and listener:
ExceptionizerBundle provide two events:
namespace Mabs\ExceptionizerBundle; final class ExceptionizerEvents { const EXCEPTIONIZER_PRE_THROW = 'exceptionizer.pre_throw'; const EXCEPTIONIZER_POST_CATCH = 'exceptionizer.post_catch'; }
exceptionizer.pre_throw : before throw Exception
exceptionizer.post_catch: (will be documented later when we speak about the Exception Catcher)
Now you can create Listeners to do a specific job when an exception will be thrown ;) and to learn more about the EventDispatcher Component in symfony2 pleaze read the documentation
License
This bundle is available under the MIT license.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-21