|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cerbero\ExceptionHandler; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Debug\ExceptionHandler; |
|
6
|
|
|
use Illuminate\Foundation\AliasLoader; |
|
7
|
|
|
use Illuminate\Support\ServiceProvider as Provider; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Service provider for the exception handler. |
|
11
|
|
|
* |
|
12
|
|
|
* @author Andrea Marco Sartori |
|
13
|
|
|
*/ |
|
14
|
|
|
class ServiceProvider extends Provider |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Add an alias for the exception handler facade. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Andrea Marco Sartori |
|
20
|
|
|
* @return void |
|
21
|
|
|
*/ |
|
22
|
|
|
public function boot() |
|
23
|
|
|
{ |
|
24
|
|
|
AliasLoader::getInstance()->alias('Exceptions', Exceptions::class); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Register the service provider. |
|
29
|
|
|
* |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
|
|
public function register() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->aliasExceptionHandler(); |
|
35
|
|
|
|
|
36
|
|
|
$this->registerExceptionHandlersRepository(); |
|
37
|
|
|
|
|
38
|
|
|
$this->extendExceptionHandler(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Create an alias for the Laravel default exception handler. |
|
43
|
|
|
* |
|
44
|
|
|
* @author Andrea Marco Sartori |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
private function aliasExceptionHandler() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->app->alias(ExceptionHandler::class, 'exceptions'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Register the custom exception handlers repository. |
|
54
|
|
|
* |
|
55
|
|
|
* @author Andrea Marco Sartori |
|
56
|
|
|
* @return void |
|
57
|
|
|
*/ |
|
58
|
|
|
private function registerExceptionHandlersRepository() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->app->singleton('exceptions.repository', Repository::class); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Extend the Laravel default exception handler. |
|
65
|
|
|
* |
|
66
|
|
|
* @author Andrea Marco Sartori |
|
67
|
|
|
* @return void |
|
68
|
|
|
*/ |
|
69
|
|
|
private function extendExceptionHandler() |
|
70
|
|
|
{ |
|
71
|
|
|
$this->app->extend(ExceptionHandler::class, function ($handler, $app) { |
|
72
|
|
|
return new Decorator($handler, $app['exceptions.repository']); |
|
73
|
|
|
}); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|