2017 © Pedro Peláez
 

library exception-bundle

Helps making your Symfony Bundle a good Exception citizen. Yes, it’s opinionated.

image

internations/exception-bundle

Helps making your Symfony Bundle a good Exception citizen. Yes, it’s opinionated.

  • Thursday, December 21, 2017
  • by lstrojny
  • Repository
  • 30 Watchers
  • 21 Stars
  • 2,324 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 12 Versions
  • 81 % Grown

The README.md

ExceptionBundle

Build Status, (*1)

Clean exception handling for your Symfony 2 bundles

ExceptionBundle helps you managing the exceptions of your bundle:, (*2)

  • 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, ExceptionBundle can help you

Usage

Generate bundle specific exception subclasses

This command will generate a bunch of exceptions, (*3)

php app/console exception:generate app/src/MyVendor/MyBundle "MyVendor\MyBundle" ExceptionInterface RuntimeException DomainException

ls app/src/MyVendor/MyBundle/Exception, (*4)

ExceptionInterface.php  RuntimeException.php  DomainException.php

cat app/src/MyVendor/MyBundle/Exception/RuntimeException.php, (*5)

<?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, (*6)

Rewrite bundle exceptions

ExceptionBundle uses PHP Parser to rewrite all throw statements in a bundle code base., (*7)

cat app/src/MyVendor/MyBundle/MyClass.php, (*8)

<?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", (*9)

Rewrites the code to:, (*10)

<?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:, (*11)

<?php
...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            ...
        );

        if ($this->debug) {
            $bundles[] = new InterNations\Bundle\ExceptionBundle\InterNationsExceptionBundle();
        }
    }
}

The Versions

21/12 2017

dev-master

9999999-dev

Helps making your Symfony Bundle a good Exception citizen. Yes, it’s opinionated.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Max Beutel

04/07 2017

5.0.1

5.0.1.0

Helps making your Symfony Bundle a good Exception citizen. Yes, it’s opinionated.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Max Beutel

19/02 2017

5.0.0

5.0.0.0

Helps making your Symfony Bundle a good Exception citizen. Yes, it’s opinionated.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Max Beutel

15/02 2017
20/05 2016
10/02 2015
11/01 2015
09/04 2014
09/04 2014
19/01 2014
04/10 2013
03/04 2013

dev-feature/psr-2-newlines

dev-feature/psr-2-newlines

Helps making your Symfony Bundle a good Exception citizen. Yes, it’s opinionated.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Max Beutel