Created
February 16, 2015 01:20
-
-
Save tristankenney/73b8dcf25aeff8a6868e to your computer and use it in GitHub Desktop.
Decorated Exception Handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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