1
|
|
|
<?php namespace Arcanedev\Support; |
2
|
|
|
|
3
|
|
|
use Illuminate\Contracts\Foundation\Application; |
4
|
|
|
use Illuminate\Foundation\AliasLoader; |
5
|
|
|
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class ServiceProvider |
9
|
|
|
* |
10
|
|
|
* @package Arcanedev\Support\Laravel |
11
|
|
|
* @author ARCANEDEV <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
abstract class ServiceProvider extends IlluminateServiceProvider |
14
|
|
|
{ |
15
|
|
|
/* ------------------------------------------------------------------------------------------------ |
16
|
|
|
| Properties |
17
|
|
|
| ------------------------------------------------------------------------------------------------ |
18
|
|
|
*/ |
19
|
|
|
/** |
20
|
|
|
* The application instance. |
21
|
|
|
* |
22
|
|
|
* @var \Illuminate\Foundation\Application |
23
|
|
|
*/ |
24
|
|
|
protected $app; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The aliases collection. |
28
|
|
|
* |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
protected $aliases = []; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Alias loader. |
35
|
|
|
* |
36
|
|
|
* @var \Illuminate\Foundation\AliasLoader |
37
|
|
|
*/ |
38
|
|
|
private $aliasLoader; |
39
|
|
|
|
40
|
|
|
/* ------------------------------------------------------------------------------------------------ |
41
|
|
|
| Constructor |
42
|
|
|
| ------------------------------------------------------------------------------------------------ |
43
|
|
|
*/ |
44
|
|
|
/** |
45
|
|
|
* Create a new service provider instance. |
46
|
|
|
* |
47
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
48
|
|
|
*/ |
49
|
9 |
|
public function __construct(Application $app) |
50
|
|
|
{ |
51
|
9 |
|
parent::__construct($app); |
|
|
|
|
52
|
|
|
|
53
|
9 |
|
$this->aliasLoader = AliasLoader::getInstance(); |
54
|
9 |
|
} |
55
|
|
|
|
56
|
|
|
/* ------------------------------------------------------------------------------------------------ |
57
|
|
|
| Main Functions |
58
|
|
|
| ------------------------------------------------------------------------------------------------ |
59
|
|
|
*/ |
60
|
|
|
/** |
61
|
|
|
* Register the service provider. |
62
|
|
|
*/ |
63
|
9 |
|
public function register() |
64
|
|
|
{ |
65
|
|
|
// |
66
|
9 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Boot the service provider. |
70
|
|
|
*/ |
71
|
|
|
public function boot() |
72
|
|
|
{ |
73
|
|
|
// |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Register a binding with the container. |
78
|
|
|
* |
79
|
|
|
* @param string|array $abstract |
80
|
|
|
* @param \Closure|string|null $concrete |
81
|
|
|
* @param bool $shared |
82
|
|
|
*/ |
83
|
|
|
public function bind($abstract, $concrete = null, $shared = false) |
84
|
|
|
{ |
85
|
|
|
$this->app->bind($abstract, $concrete, $shared); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Register a shared binding in the container. |
90
|
|
|
* |
91
|
|
|
* @param string|array $abstract |
92
|
|
|
* @param \Closure|string|null $concrete |
93
|
|
|
*/ |
94
|
|
|
protected function singleton($abstract, $concrete = null) |
95
|
|
|
{ |
96
|
|
|
$this->app->singleton($abstract, $concrete); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Register a service provider. |
101
|
|
|
* |
102
|
|
|
* @param \Illuminate\Support\ServiceProvider|string $provider |
103
|
|
|
* @param array $options |
104
|
|
|
* @param bool $force |
105
|
|
|
* |
106
|
|
|
* @return \Illuminate\Support\ServiceProvider |
107
|
|
|
*/ |
108
|
|
|
protected function registerProvider($provider, array $options = [], $force = false) |
109
|
|
|
{ |
110
|
|
|
return $this->app->register($provider, $options, $force); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Register multiple service providers. |
115
|
|
|
* |
116
|
|
|
* @param array $providers |
117
|
|
|
*/ |
118
|
|
|
protected function registerProviders(array $providers) |
119
|
|
|
{ |
120
|
|
|
foreach ($providers as $provider) { |
121
|
|
|
$this->registerProvider($provider); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Register a console service provider. |
127
|
|
|
* |
128
|
|
|
* @param \Illuminate\Support\ServiceProvider|string $provider |
129
|
|
|
* @param array $options |
130
|
|
|
* @param bool $force |
131
|
|
|
* |
132
|
|
|
* @return \Illuminate\Support\ServiceProvider|null |
133
|
|
|
*/ |
134
|
|
|
protected function registerConsoleServiceProvider($provider, array $options = [], $force = false) |
135
|
|
|
{ |
136
|
|
|
return $this->app->runningInConsole() |
137
|
|
|
? $this->registerProvider($provider, $options, $force) |
138
|
|
|
: null; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Register aliases (Facades). |
143
|
|
|
*/ |
144
|
|
|
protected function registerAliases() |
145
|
|
|
{ |
146
|
|
|
$loader = $this->aliasLoader; |
147
|
|
|
|
148
|
|
|
$this->app->booting(function() use ($loader) { |
149
|
|
|
foreach ($this->aliases as $class => $alias) { |
150
|
|
|
$loader->alias($class, $alias); |
151
|
|
|
} |
152
|
|
|
}); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Add an aliases to the loader. |
157
|
|
|
* |
158
|
|
|
* @param array $aliases |
159
|
|
|
* |
160
|
|
|
* @return self |
161
|
|
|
*/ |
162
|
|
|
protected function aliases(array $aliases) |
163
|
|
|
{ |
164
|
|
|
foreach ($aliases as $class => $alias) { |
165
|
|
|
$this->alias($class, $alias); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Add an alias to the loader. |
173
|
|
|
* |
174
|
|
|
* @param string $class |
175
|
|
|
* @param string $alias |
176
|
|
|
* |
177
|
|
|
* @return self |
178
|
|
|
*/ |
179
|
|
|
protected function alias($class, $alias) |
180
|
|
|
{ |
181
|
|
|
$this->aliases[$class] = $alias; |
182
|
|
|
|
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/* ------------------------------------------------------------------------------------------------ |
187
|
|
|
| Services |
188
|
|
|
| ------------------------------------------------------------------------------------------------ |
189
|
|
|
*/ |
190
|
|
|
/** |
191
|
|
|
* Get the config repository instance. |
192
|
|
|
* |
193
|
|
|
* @return \Illuminate\Config\Repository |
194
|
|
|
*/ |
195
|
|
|
protected function config() |
196
|
|
|
{ |
197
|
|
|
return $this->app['config']; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Get the filesystem instance. |
202
|
|
|
* |
203
|
|
|
* @return \Illuminate\Filesystem\Filesystem |
204
|
|
|
*/ |
205
|
|
|
protected function filesystem() |
206
|
|
|
{ |
207
|
|
|
return $this->app['files']; |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.