2017 © Pedro Peláez
 

library response-exception

Response exception for Laravel4

image

desmart/response-exception

Response exception for Laravel4

  • Friday, February 21, 2014
  • by DeSmart
  • Repository
  • 10 Watchers
  • 0 Stars
  • 357 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Response Exception

Response exception for Laravel4 is.. exception which returns response., (*1)

Install notes

Add desmart/response-exception as a requirement to composer.json:, (*2)

{
  "require": {
    "desmart/response-exception": "1.1.*"
  }
}

Update your packages with composer update or install with composer install., (*3)

To add error handler add 'DeSmart\ResponseException\ResponseExceptionServiceProvider', to providers in app/config/app.php., (*4)

Other way of adding the handler is to add App::error() in app/filters.php:, (*5)

App::error(DeSmart\ResponseException\ErrorHandlerFactory::make());

Just remember to add it after the registration of other App::error() handlers., (*6)

Why ?

Let's take a look at desmart/laravel-layout. It's a complex controller calling many actions., (*7)

Doing redirects in one of the actions is quite painful. That's because each action returns only a part of bigger response. The only way to return a response which will overwrite the big part is throwing of exception., (*8)

That's not the best design (exceptions aren't for that!), but it works and gives a chance to generate complete response from the smallest part of application., (*9)

Use cases

This package is useless for standard Laravel applications. Probably it fit's best with desmart/laravel-layout since it's a wicked controller., (*10)

Also in some edge cases it can be used for situations when some part of application needs to send own response during controller dispatch., (*11)

Examples

use DeSmart\ResponseException\Exception as ResponseException;

ResponseException::make('foo'); // sends 'foo' response

// There's an option to make chained exceptions
ResponseException::chain(Redirect::to('/'))
  ->withInput()
  ->fire();

The hack

In Laravel response may by returned in many parts of request cycle:, (*12)

  • before routing (App::before())
  • during route dispatch
  • when exception is thrown (App::error)

Our hack is using exceptions to take advantage of App::error(). When error handler returns a value that value is treated as a response and is returned to client., (*13)

Since throwing an exception breaks normal code execution it's the best way to deliver fast a response., (*14)

There's a catch. Every exception is logged to file. The only way to get pass it is to register error handler as the last one. Laravel puts every error handler on top of handlers stack. When one of them returns response the others are not called., (*15)

The Versions

21/02 2014

dev-master

9999999-dev

Response exception for Laravel4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Radoslaw Mejer

21/02 2014

1.1.0

1.1.0.0

Response exception for Laravel4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Radoslaw Mejer

15/05 2013

1.0.0

1.0.0.0

Response exception for Laravel4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Radoslaw Mejer