Completed
Branch master (10c809)
by Andrea Marco
07:44 queued 05:58
created

ServiceProvider::aliasExceptionHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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