|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HughCube\ACMClient; |
|
4
|
|
|
|
|
5
|
|
|
use HughCube\ACMClient\Commands\SyncConfig; |
|
6
|
|
|
use Illuminate\Contracts\Support\DeferrableProvider; |
|
7
|
|
|
use Illuminate\Foundation\Application as LaravelApplication; |
|
8
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
|
9
|
|
|
use Laravel\Lumen\Application as LumenApplication; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class ACMServiceProvider |
|
13
|
|
|
* @package Illuminate\Redis |
|
14
|
|
|
* |
|
15
|
|
|
* @property LaravelApplication|LumenApplication $app |
|
16
|
|
|
* |
|
17
|
|
|
*/ |
|
18
|
|
|
class ServiceProvider extends BaseServiceProvider implements DeferrableProvider |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Boot the service provider. |
|
22
|
|
|
* |
|
23
|
|
|
* @return void |
|
24
|
|
|
*/ |
|
25
|
|
|
public function boot() |
|
26
|
|
|
{ |
|
27
|
|
|
$source = realpath($raw = __DIR__ . '/../config/acm.php') ?: $raw; |
|
28
|
|
|
|
|
29
|
|
|
if ($this->app instanceof LumenApplication) { |
|
30
|
|
|
$this->app->configure('acm'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if ($this->app instanceof LaravelApplication && !$this->app->configurationIsCached()) { |
|
34
|
|
|
$this->mergeConfigFrom($source, 'acm'); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Register the service provider. |
|
41
|
|
|
* |
|
42
|
|
|
* @return void |
|
43
|
|
|
*/ |
|
44
|
|
|
public function register() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->app->singleton('acm', function ($app) { |
|
47
|
|
|
$config = $app->make('config')->get('acm', []); |
|
48
|
|
|
|
|
49
|
|
|
return new Manager($app, $config); |
|
50
|
|
|
}); |
|
51
|
|
|
|
|
52
|
|
|
if ($this->app->runningInConsole()) { |
|
53
|
|
|
$this->registerCommand(); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get the services provided by the provider. |
|
59
|
|
|
* |
|
60
|
|
|
* @return array |
|
61
|
|
|
*/ |
|
62
|
|
|
public function provides() |
|
63
|
|
|
{ |
|
64
|
|
|
return []; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* 注册 $command |
|
69
|
|
|
* |
|
70
|
|
|
* @param $commandClass |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function registerCommand() |
|
73
|
|
|
{ |
|
74
|
|
|
$commands = [ |
|
75
|
|
|
SyncConfig::class |
|
76
|
|
|
]; |
|
77
|
|
|
|
|
78
|
|
|
foreach ($commands as $command) { |
|
79
|
|
|
$this->app->singleton($command, function () use ($command) { |
|
80
|
|
|
return new $command(); |
|
81
|
|
|
}); |
|
82
|
|
|
$this->commands([$command]); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|