1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CodingSocks\UploadHandler; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
|
7
|
|
|
class UploadHandlerServiceProvider extends ServiceProvider |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Bootstrap any package services. |
11
|
|
|
* |
12
|
|
|
* @return void |
13
|
|
|
*/ |
14
|
156 |
|
public function boot() |
15
|
|
|
{ |
16
|
156 |
|
$this->setupConfig(); |
17
|
156 |
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Setup the config. |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
156 |
|
protected function setupConfig() |
25
|
|
|
{ |
26
|
156 |
|
$source = realpath(__DIR__ . '/../config/upload-handler.php'); |
27
|
156 |
|
$this->publishes([$source => config_path('upload-handler.php')]); |
28
|
|
|
|
29
|
156 |
|
$this->mergeConfigFrom($source, 'upload-handler'); |
30
|
156 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Register any package services. |
34
|
|
|
* |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
156 |
|
public function register() |
38
|
|
|
{ |
39
|
156 |
|
$this->registerUploadHandler(); |
40
|
156 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Register the Upload Handler instance. |
44
|
|
|
* |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
156 |
|
protected function registerUploadHandler() |
48
|
|
|
{ |
49
|
156 |
|
$this->registerUploadManager(); |
50
|
156 |
|
$this->registerIdentityManager(); |
51
|
|
|
|
52
|
156 |
|
$this->app->singleton(UploadHandler::class, function () { |
53
|
|
|
/** @var \Illuminate\Support\Manager $uploadManager */ |
54
|
153 |
|
$uploadManager = $this->app['upload-handler.upload-manager']; |
55
|
|
|
|
56
|
153 |
|
$storageConfig = new StorageConfig($this->app->make('config')->get('upload-handler')); |
57
|
|
|
|
58
|
153 |
|
return new UploadHandler($uploadManager->driver(), $storageConfig); |
59
|
156 |
|
}); |
60
|
156 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Register the Upload Manager instance. |
64
|
|
|
* |
65
|
|
|
* @return void |
66
|
|
|
*/ |
67
|
156 |
|
protected function registerUploadManager() |
68
|
|
|
{ |
69
|
156 |
|
$this->app->singleton('upload-handler.upload-manager', function () { |
70
|
153 |
|
return new UploadManager($this->app); |
71
|
156 |
|
}); |
72
|
156 |
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Register the Upload Manager instance. |
76
|
|
|
* |
77
|
|
|
* @return void |
78
|
|
|
*/ |
79
|
156 |
|
protected function registerIdentityManager() |
80
|
|
|
{ |
81
|
156 |
|
$this->app->singleton('upload-handler.identity-manager', function () { |
82
|
131 |
|
return new IdentityManager($this->app); |
83
|
156 |
|
}); |
84
|
156 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get the services provided by the provider. |
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public function provides() |
92
|
|
|
{ |
93
|
|
|
return [ |
94
|
|
|
UploadHandler::class, |
95
|
|
|
'upload-handler.upload-manager', |
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|