Skip to content

Instantly share code, notes, and snippets.

@tristankenney
Created February 16, 2015 01:20
Show Gist options
  • Save tristankenney/73b8dcf25aeff8a6868e to your computer and use it in GitHub Desktop.
Save tristankenney/73b8dcf25aeff8a6868e to your computer and use it in GitHub Desktop.
Decorated Exception Handler
class MyHandler implements ExceptionHandlerInterface
{
protected $handler;
//Accept the interface, rather than the implementation
public function __construct(ExceptionHandlerInterface $handler)
{
$this->handler = $handler;
}
public function report(Exception $e)
{
//my cool stuff goes here
return $this->handler->report($e);
}
/* Yup, you need to implement them all, even if they are just proxying straight through */
public function render($request, Exception $e)
{
return $this->handler->report($request, $e);
}
public function renderForConsole($output, Exception $e)
{
return $this->handler->report($output, $e);
}
}
class MyServiceProvider
{
public function register()
{
//Grabs the instance via the interface
$handler = $this->app->make('Illuminate\Contracts\Debug\ExceptionHandler');
$this->app->instance('Illuminate\Contracts\Debug\ExceptionHandler', new MyHandler($handler));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment