|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bavix\CupKit; |
|
4
|
|
|
|
|
5
|
|
|
use Bavix\CupKit\Commands\CDNCommand; |
|
6
|
|
|
use Bavix\CupKit\Storage\CupAdapter; |
|
7
|
|
|
use Illuminate\Support\Facades\Storage; |
|
8
|
|
|
use Illuminate\Support\ServiceProvider; |
|
9
|
|
|
use League\Flysystem\Filesystem; |
|
10
|
|
|
|
|
11
|
|
|
class CupKitServiceProvider extends ServiceProvider |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
public const SINGLETON_CLIENT_CREDENTIALS = 'bavix.cupkit::client_credentials'; |
|
15
|
|
|
public const SINGLETON_IDENTITY = 'bavix.cupkit::identity'; |
|
16
|
|
|
public const SINGLETON_CLIENT = 'bavix.cupkit::client'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @return void |
|
20
|
|
|
*/ |
|
21
|
|
|
public function boot(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$this->registerConfigs(); |
|
24
|
|
|
$this->registerCommands(); |
|
25
|
|
|
$this->registerSingletons(); |
|
26
|
|
|
$this->registerStorage(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function registerCommands(): void |
|
33
|
|
|
{ |
|
34
|
|
|
if (!$this->app->runningInConsole()) { |
|
35
|
|
|
return; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$this->commands([CDNCommand::class]); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return void |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function registerSingletons(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$this->app->singleton(self::SINGLETON_CLIENT_CREDENTIALS, function () { |
|
47
|
|
|
$class = config('corundum.client_credentials'); |
|
48
|
|
|
return new $class( |
|
49
|
|
|
\config('corundum.base_url', ''), |
|
50
|
|
|
\config('corundum.client_id', ''), |
|
51
|
|
|
\config('corundum.client_secret', '') |
|
52
|
|
|
); |
|
53
|
|
|
}); |
|
54
|
|
|
|
|
55
|
|
|
$this->app->singleton(self::SINGLETON_IDENTITY, function () { |
|
56
|
|
|
$class = config('corundum.identity'); |
|
57
|
|
|
return new $class( |
|
58
|
|
|
app(self::SINGLETON_CLIENT_CREDENTIALS), |
|
59
|
|
|
\config('corundum.username', ''), |
|
60
|
|
|
\config('corundum.password', '') |
|
61
|
|
|
); |
|
62
|
|
|
}); |
|
63
|
|
|
|
|
64
|
|
|
$this->app->singleton(self::SINGLETON_CLIENT, function () { |
|
65
|
|
|
$class = config('corundum.client'); |
|
66
|
|
|
return new $class(app(self::SINGLETON_IDENTITY)); |
|
67
|
|
|
}); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return void |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function registerStorage(): void |
|
74
|
|
|
{ |
|
75
|
|
|
Storage::extend('corundum', function ($app, $config) { |
|
76
|
|
|
return new Filesystem(new CupAdapter($app, $config)); |
|
77
|
|
|
}); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return void |
|
82
|
|
|
*/ |
|
83
|
|
|
protected function registerConfigs(): void |
|
84
|
|
|
{ |
|
85
|
|
|
if (!$this->app->runningInConsole()) { |
|
86
|
|
|
return; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
$this->publishes([ |
|
90
|
|
|
\dirname(__DIR__) . '/config/config.php' => config_path('corundum.php'), |
|
91
|
|
|
], 'laravel-cupkit-config'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|