1
|
|
|
<?php namespace Arcanesoft\Auth\Providers; |
2
|
|
|
|
3
|
|
|
use Arcanedev\Gravatar\GravatarServiceProvider; |
4
|
|
|
use Arcanedev\LaravelAuth\LaravelAuthServiceProvider; |
5
|
|
|
use Arcanedev\LaravelAuth\Services\SocialAuthenticator; |
6
|
|
|
use Arcanedev\Support\ServiceProvider; |
7
|
|
|
use Illuminate\Support\Arr; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class PackagesServiceProvider |
11
|
|
|
* |
12
|
|
|
* @package Arcanesoft\Auth\Providers |
13
|
|
|
* @author ARCANEDEV <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class PackagesServiceProvider extends ServiceProvider |
16
|
|
|
{ |
17
|
|
|
/* ------------------------------------------------------------------------------------------------ |
18
|
|
|
| Main Functions |
19
|
|
|
| ------------------------------------------------------------------------------------------------ |
20
|
|
|
*/ |
21
|
|
|
/** |
22
|
|
|
* Register the service provider. |
23
|
|
|
*/ |
24
|
12 |
|
public function register() |
25
|
|
|
{ |
26
|
12 |
|
$this->registerGravatarPackage(); |
27
|
12 |
|
$this->registerLaravelAuthPackage(); |
28
|
12 |
|
} |
29
|
|
|
|
30
|
|
|
/* ------------------------------------------------------------------------------------------------ |
31
|
|
|
| Register Packages |
32
|
|
|
| ------------------------------------------------------------------------------------------------ |
33
|
|
|
*/ |
34
|
|
|
/** |
35
|
|
|
* Register the gravatar package. |
36
|
|
|
*/ |
37
|
12 |
|
private function registerGravatarPackage() |
38
|
|
|
{ |
39
|
12 |
|
$this->registerProvider(GravatarServiceProvider::class); |
40
|
12 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Register the laravel auth package. |
44
|
|
|
*/ |
45
|
12 |
|
private function registerLaravelAuthPackage() |
46
|
|
|
{ |
47
|
12 |
|
$this->registerProvider(LaravelAuthServiceProvider::class); |
48
|
|
|
|
49
|
12 |
|
$this->configLaravelAuthPackage(); |
50
|
12 |
|
$this->rebindModels(); |
51
|
12 |
|
$this->registerDependencies(); |
|
|
|
|
52
|
12 |
|
} |
53
|
|
|
|
54
|
|
|
/* ------------------------------------------------------------------------------------------------ |
55
|
|
|
| Config Packages |
56
|
|
|
| ------------------------------------------------------------------------------------------------ |
57
|
|
|
*/ |
58
|
|
|
/** |
59
|
|
|
* Config the laravel auth package (override). |
60
|
|
|
*/ |
61
|
12 |
|
private function configLaravelAuthPackage() |
62
|
|
|
{ |
63
|
|
|
/** @var \Illuminate\Contracts\Config\Repository $config */ |
64
|
12 |
|
$config = $this->config(); |
65
|
12 |
|
$config->set('laravel-auth', Arr::except($config->get('arcanesoft.auth'), ['route', 'hasher'])); |
66
|
|
|
|
67
|
12 |
|
if (SocialAuthenticator::isEnabled()) { |
68
|
|
|
$this->registerProvider(\Laravel\Socialite\SocialiteServiceProvider::class); |
69
|
|
|
} |
70
|
12 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Rebind the auth models. |
74
|
|
|
*/ |
75
|
12 |
|
private function rebindModels() |
76
|
|
|
{ |
77
|
12 |
|
$config = $this->config(); |
78
|
|
|
$bindings = [ |
79
|
|
|
[ |
80
|
12 |
|
'abstract' => \Arcanesoft\Contracts\Auth\Models\User::class, |
81
|
12 |
|
'concrete' => $config->get('arcanesoft.auth.users.model'), |
82
|
12 |
|
],[ |
83
|
12 |
|
'abstract' => \Arcanesoft\Contracts\Auth\Models\Role::class, |
84
|
12 |
|
'concrete' => $config->get('arcanesoft.auth.roles.model'), |
85
|
12 |
|
],[ |
86
|
12 |
|
'abstract' => \Arcanesoft\Contracts\Auth\Models\Permission::class, |
87
|
12 |
|
'concrete' => $config->get('arcanesoft.auth.permissions.model'), |
88
|
12 |
|
],[ |
89
|
12 |
|
'abstract' => \Arcanesoft\Contracts\Auth\Models\PermissionsGroup::class, |
90
|
12 |
|
'concrete' => $config->get('arcanesoft.auth.permissions-groups.model'), |
91
|
12 |
|
], |
92
|
12 |
|
]; |
93
|
|
|
|
94
|
12 |
|
foreach ($bindings as $binding) { |
95
|
12 |
|
$this->bind($binding['abstract'], $binding['concrete']); |
96
|
12 |
|
} |
97
|
12 |
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Register the package dependencies. |
101
|
|
|
*/ |
102
|
12 |
|
private function registerDependencies() |
103
|
|
|
{ |
104
|
|
|
// |
105
|
12 |
|
} |
106
|
|
|
} |
107
|
|
|
|
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: