|
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
|
|
|
/** |
|
21
|
|
|
* The application instance. |
|
22
|
|
|
* |
|
23
|
|
|
* @var \Illuminate\Foundation\Application |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $app; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The aliases collection. |
|
29
|
|
|
* |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $aliases = []; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Alias loader. |
|
36
|
|
|
* |
|
37
|
|
|
* @var \Illuminate\Foundation\AliasLoader |
|
38
|
|
|
*/ |
|
39
|
|
|
private $aliasLoader; |
|
40
|
|
|
|
|
41
|
|
|
/* ----------------------------------------------------------------- |
|
42
|
|
|
| Constructor |
|
43
|
|
|
| ----------------------------------------------------------------- |
|
44
|
|
|
*/ |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Create a new service provider instance. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
|
50
|
|
|
*/ |
|
51
|
6 |
|
public function __construct(Application $app) |
|
52
|
|
|
{ |
|
53
|
6 |
|
parent::__construct($app); |
|
54
|
|
|
|
|
55
|
6 |
|
$this->aliasLoader = AliasLoader::getInstance(); |
|
56
|
6 |
|
} |
|
57
|
|
|
|
|
58
|
|
|
/* ----------------------------------------------------------------- |
|
59
|
|
|
| Main Methods |
|
60
|
|
|
| ----------------------------------------------------------------- |
|
61
|
|
|
*/ |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Register the service provider. |
|
65
|
|
|
*/ |
|
66
|
6 |
|
public function register() |
|
67
|
|
|
{ |
|
68
|
|
|
// |
|
69
|
6 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Boot the service provider. |
|
73
|
|
|
*/ |
|
74
|
|
|
public function boot() |
|
75
|
|
|
{ |
|
76
|
|
|
// |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Register a binding with the container. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string|array $abstract |
|
83
|
|
|
* @param \Closure|string|null $concrete |
|
84
|
|
|
* @param bool $shared |
|
85
|
|
|
*/ |
|
86
|
|
|
public function bind($abstract, $concrete = null, $shared = false) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->app->bind($abstract, $concrete, $shared); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Register a shared binding in the container. |
|
93
|
|
|
* |
|
94
|
|
|
* @param string|array $abstract |
|
95
|
|
|
* @param \Closure|string|null $concrete |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function singleton($abstract, $concrete = null) |
|
98
|
|
|
{ |
|
99
|
|
|
$this->app->singleton($abstract, $concrete); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Register a service provider. |
|
104
|
|
|
* |
|
105
|
|
|
* @param \Illuminate\Support\ServiceProvider|string $provider |
|
106
|
|
|
* @param array $options |
|
107
|
|
|
* @param bool $force |
|
108
|
|
|
* |
|
109
|
|
|
* @return \Illuminate\Support\ServiceProvider |
|
110
|
|
|
*/ |
|
111
|
|
|
protected function registerProvider($provider, array $options = [], $force = false) |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->app->register($provider, $options, $force); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Register multiple service providers. |
|
118
|
|
|
* |
|
119
|
|
|
* @param array $providers |
|
120
|
|
|
*/ |
|
121
|
|
|
protected function registerProviders(array $providers) |
|
122
|
|
|
{ |
|
123
|
|
|
foreach ($providers as $provider) { |
|
124
|
|
|
$this->registerProvider($provider); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Register a console service provider. |
|
130
|
|
|
* |
|
131
|
|
|
* @param \Illuminate\Support\ServiceProvider|string $provider |
|
132
|
|
|
* @param array $options |
|
133
|
|
|
* @param bool $force |
|
134
|
|
|
* |
|
135
|
|
|
* @return \Illuminate\Support\ServiceProvider|null |
|
136
|
|
|
*/ |
|
137
|
|
|
protected function registerConsoleServiceProvider($provider, array $options = [], $force = false) |
|
138
|
|
|
{ |
|
139
|
|
|
if ($this->app->runningInConsole()) |
|
140
|
|
|
return $this->registerProvider($provider, $options, $force); |
|
141
|
|
|
|
|
142
|
|
|
return null; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Register aliases (Facades). |
|
147
|
|
|
*/ |
|
148
|
|
|
protected function registerAliases() |
|
149
|
|
|
{ |
|
150
|
|
|
$loader = $this->aliasLoader; |
|
151
|
|
|
|
|
152
|
|
|
$this->app->booting(function() use ($loader) { |
|
153
|
|
|
foreach ($this->aliases as $class => $alias) { |
|
154
|
|
|
$loader->alias($class, $alias); |
|
155
|
|
|
} |
|
156
|
|
|
}); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Add an aliases to the loader. |
|
161
|
|
|
* |
|
162
|
|
|
* @param array $aliases |
|
163
|
|
|
* |
|
164
|
|
|
* @return self |
|
165
|
|
|
*/ |
|
166
|
|
|
protected function aliases(array $aliases) |
|
167
|
|
|
{ |
|
168
|
|
|
foreach ($aliases as $class => $alias) { |
|
169
|
|
|
$this->alias($class, $alias); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
return $this; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Add an alias to the loader. |
|
177
|
|
|
* |
|
178
|
|
|
* @param string $class |
|
179
|
|
|
* @param string $alias |
|
180
|
|
|
* |
|
181
|
|
|
* @return self |
|
182
|
|
|
*/ |
|
183
|
|
|
protected function alias($class, $alias) |
|
184
|
|
|
{ |
|
185
|
|
|
$this->aliases[$class] = $alias; |
|
186
|
|
|
|
|
187
|
|
|
return $this; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/* ----------------------------------------------------------------- |
|
191
|
|
|
| Services |
|
192
|
|
|
| ----------------------------------------------------------------- |
|
193
|
|
|
*/ |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Get the config repository instance. |
|
197
|
|
|
* |
|
198
|
|
|
* @return \Illuminate\Config\Repository |
|
199
|
|
|
*/ |
|
200
|
|
|
protected function config() |
|
201
|
|
|
{ |
|
202
|
|
|
return $this->app['config']; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Get the filesystem instance. |
|
207
|
|
|
* |
|
208
|
|
|
* @return \Illuminate\Filesystem\Filesystem |
|
209
|
|
|
*/ |
|
210
|
|
|
protected function filesystem() |
|
211
|
|
|
{ |
|
212
|
|
|
return $this->app['files']; |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
|