LaravelLoggerServiceProvider::getListeners()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace jeremykenedy\LaravelLogger;
4
5
use Illuminate\Routing\Router;
6
use Illuminate\Support\Facades\Event;
7
use Illuminate\Support\ServiceProvider;
8
use jeremykenedy\LaravelLogger\App\Http\Middleware\LogActivity;
9
10
class LaravelLoggerServiceProvider extends ServiceProvider
11
{
12
    const DISABLE_DEFAULT_ROUTES_CONFIG = 'laravel-logger.disableRoutes';
13
14
    /**
15
     * Indicates if loading of the provider is deferred.
16
     *
17
     * @var bool
18
     */
19
    protected $defer = false;
20
21
    /**
22
     * The event listener mappings for the applications auth scafolding.
23
     *
24
     * @var array
25
     */
26
    protected $listeners = [
27
28
        'Illuminate\Auth\Events\Attempting' => [
29
            'jeremykenedy\LaravelLogger\App\Listeners\LogAuthenticationAttempt',
30
        ],
31
32
        'Illuminate\Auth\Events\Authenticated' => [
33
            'jeremykenedy\LaravelLogger\App\Listeners\LogAuthenticated',
34
        ],
35
36
        'Illuminate\Auth\Events\Login' => [
37
            'jeremykenedy\LaravelLogger\App\Listeners\LogSuccessfulLogin',
38
        ],
39
40
        'Illuminate\Auth\Events\Failed' => [
41
            'jeremykenedy\LaravelLogger\App\Listeners\LogFailedLogin',
42
        ],
43
44
        'Illuminate\Auth\Events\Logout' => [
45
            'jeremykenedy\LaravelLogger\App\Listeners\LogSuccessfulLogout',
46
        ],
47
48
        'Illuminate\Auth\Events\Lockout' => [
49
            'jeremykenedy\LaravelLogger\App\Listeners\LogLockout',
50
        ],
51
52
        'Illuminate\Auth\Events\PasswordReset' => [
53
            'jeremykenedy\LaravelLogger\App\Listeners\LogPasswordReset',
54
        ],
55
56
    ];
57
58
    /**
59
     * Bootstrap the application services.
60
     *
61
     * @return void
62
     */
63
    public function boot(Router $router)
64
    {
65
        $router->middlewareGroup('activity', [LogActivity::class]);
66
        $this->loadTranslationsFrom(__DIR__.'/resources/lang/', 'LaravelLogger');
67
    }
68
69
    /**
70
     * Register the application services.
71
     *
72
     * @return void
73
     */
74
    public function register()
75
    {
76
        if (file_exists(config_path('laravel-logger.php'))) {
0 ignored issues
show
Bug introduced by
The function config_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

76
        if (file_exists(/** @scrutinizer ignore-call */ config_path('laravel-logger.php'))) {
Loading history...
77
            $this->mergeConfigFrom(config_path('laravel-logger.php'), 'LaravelLogger');
78
        } else {
79
            $this->mergeConfigFrom(__DIR__.'/config/laravel-logger.php', 'LaravelLogger');
80
        }
81
82
        if (config(self::DISABLE_DEFAULT_ROUTES_CONFIG) == false) {
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

82
        if (/** @scrutinizer ignore-call */ config(self::DISABLE_DEFAULT_ROUTES_CONFIG) == false) {
Loading history...
83
            $this->loadRoutesFrom(__DIR__.'/routes/web.php');
84
        }
85
86
        $this->loadViewsFrom(__DIR__.'/resources/views/', 'LaravelLogger');
87
        $this->loadMigrationsFrom(__DIR__.'/database/migrations');
88
89
        $this->registerEventListeners();
90
        $this->publishFiles();
91
    }
92
93
    /**
94
     * Get the list of listeners and events.
95
     *
96
     * @return array
97
     */
98
    private function getListeners()
99
    {
100
        return $this->listeners;
101
    }
102
103
    /**
104
     * Register the list of listeners and events.
105
     *
106
     * @return void
107
     */
108
    private function registerEventListeners()
109
    {
110
        $listeners = $this->getListeners();
111
        foreach ($listeners as $listenerKey => $listenerValues) {
112
            foreach ($listenerValues as $listenerValue) {
113
                Event::listen(
114
                    $listenerKey,
115
                    $listenerValue
116
                );
117
            }
118
        }
119
    }
120
121
    /**
122
     * Publish files for Laravel Logger.
123
     *
124
     * @return void
125
     */
126
    private function publishFiles()
127
    {
128
        $publishTag = 'LaravelLogger';
129
130
        $this->publishes([
131
            __DIR__.'/config/laravel-logger.php' => base_path('config/laravel-logger.php'),
0 ignored issues
show
Bug introduced by
The function base_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

131
            __DIR__.'/config/laravel-logger.php' => /** @scrutinizer ignore-call */ base_path('config/laravel-logger.php'),
Loading history...
132
        ], $publishTag);
133
134
        $this->publishes([
135
            __DIR__.'/resources/views' => base_path('resources/views/vendor/'.$publishTag),
136
        ], $publishTag);
137
138
        $this->publishes([
139
            __DIR__.'/resources/lang' => base_path('resources/lang/vendor/'.$publishTag),
140
        ], $publishTag);
141
    }
142
}
143