|
1
|
|
|
<?php namespace Arcanedev\LaravelAuth; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\Support\PackageServiceProvider as ServiceProvider; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class LaravelAuthServiceProvider |
|
7
|
|
|
* |
|
8
|
|
|
* @package Arcanedev\LaravelAuth |
|
9
|
|
|
* @author ARCANEDEV <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
class LaravelAuthServiceProvider extends ServiceProvider |
|
12
|
|
|
{ |
|
13
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
14
|
|
|
| Properties |
|
15
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
16
|
|
|
*/ |
|
17
|
|
|
/** |
|
18
|
|
|
* Vendor name. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $vendor = 'arcanedev'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Package name. |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $package = 'laravel-auth'; |
|
30
|
|
|
|
|
31
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
32
|
|
|
| Getters & Setters |
|
33
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
34
|
|
|
*/ |
|
35
|
|
|
/** |
|
36
|
|
|
* Get the base path of the package. |
|
37
|
|
|
* |
|
38
|
|
|
* @return string |
|
39
|
|
|
*/ |
|
40
|
260 |
|
public function getBasePath() |
|
41
|
|
|
{ |
|
42
|
260 |
|
return dirname(__DIR__); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
46
|
|
|
| Main Functions |
|
47
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
48
|
|
|
*/ |
|
49
|
|
|
/** |
|
50
|
|
|
* Register the service provider. |
|
51
|
|
|
*/ |
|
52
|
260 |
|
public function register() |
|
53
|
|
|
{ |
|
54
|
260 |
|
$this->registerConfig(); |
|
55
|
|
|
|
|
56
|
260 |
|
$this->bindModels(); |
|
57
|
|
|
|
|
58
|
260 |
|
if ($this->app['config']->get('laravel-auth.user-observers', false)) { |
|
59
|
260 |
|
$this->app->register(Providers\EventServiceProvider::class); |
|
60
|
195 |
|
} |
|
61
|
260 |
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Boot the service provider. |
|
65
|
|
|
*/ |
|
66
|
260 |
|
public function boot() |
|
67
|
|
|
{ |
|
68
|
260 |
|
parent::boot(); |
|
69
|
|
|
|
|
70
|
260 |
|
$this->registerPublishes(); |
|
71
|
260 |
|
$this->registerBladeDirectives(); |
|
|
|
|
|
|
72
|
260 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get the services provided by the provider. |
|
76
|
|
|
* |
|
77
|
|
|
* @return array |
|
78
|
|
|
*/ |
|
79
|
4 |
|
public function provides() |
|
80
|
|
|
{ |
|
81
|
|
|
return [ |
|
82
|
|
|
// |
|
83
|
4 |
|
]; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
87
|
|
|
| Other Functions |
|
88
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
89
|
|
|
*/ |
|
90
|
|
|
/** |
|
91
|
|
|
* Register all publishable stuff. |
|
92
|
|
|
*/ |
|
93
|
260 |
|
private function registerPublishes() |
|
94
|
|
|
{ |
|
95
|
260 |
|
$this->publishes([ |
|
96
|
260 |
|
$this->getConfigFile() => config_path("{$this->package}.php"), |
|
97
|
260 |
|
], 'config'); |
|
98
|
|
|
|
|
99
|
260 |
|
$this->publishes([ |
|
100
|
260 |
|
$this->getBasePath() . DS . 'database/migrations' => database_path('migrations'), |
|
101
|
260 |
|
], 'migrations'); |
|
102
|
|
|
|
|
103
|
260 |
|
$this->publishes([ |
|
104
|
260 |
|
$this->getBasePath() . DS . 'database/factories' => database_path('factories'), |
|
105
|
260 |
|
], 'factories'); |
|
106
|
260 |
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Register blade directives |
|
110
|
|
|
*/ |
|
111
|
260 |
|
private function registerBladeDirectives() |
|
112
|
|
|
{ |
|
113
|
|
|
// Coming soon |
|
114
|
260 |
|
} |
|
115
|
|
|
|
|
116
|
260 |
|
private function bindModels() |
|
117
|
|
|
{ |
|
118
|
|
|
/** @var \Illuminate\Contracts\Config\Repository $config */ |
|
119
|
260 |
|
$config = $this->app['config']; |
|
120
|
|
|
|
|
121
|
260 |
|
$this->bind( |
|
122
|
260 |
|
\Arcanesoft\Contracts\Auth\Models\User::class, |
|
123
|
260 |
|
$config->get('laravel-auth.users.model') |
|
124
|
195 |
|
); |
|
125
|
|
|
|
|
126
|
260 |
|
$this->bind( |
|
127
|
260 |
|
\Arcanesoft\Contracts\Auth\Models\Role::class, |
|
128
|
260 |
|
$config->get('laravel-auth.roles.model') |
|
129
|
195 |
|
); |
|
130
|
|
|
|
|
131
|
260 |
|
$this->bind( |
|
132
|
260 |
|
\Arcanesoft\Contracts\Auth\Models\Permission::class, |
|
133
|
260 |
|
$config->get('laravel-auth.permissions.model') |
|
134
|
195 |
|
); |
|
135
|
|
|
|
|
136
|
260 |
|
$this->bind( |
|
137
|
260 |
|
\Arcanesoft\Contracts\Auth\Models\PermissionsGroup::class, |
|
138
|
260 |
|
$config->get('laravel-auth.permissions-groups.model') |
|
139
|
195 |
|
); |
|
140
|
260 |
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: