5
5
use Illuminate \Console \Scheduling \Schedule ;
6
6
use Illuminate \Http \Request ;
7
7
use Illuminate \Support \Arr ;
8
+ use Illuminate \Support \Facades \Storage ;
8
9
use Illuminate \Support \ServiceProvider ;
9
10
use Pion \Laravel \ChunkUpload \Commands \ClearChunksCommand ;
10
11
use Pion \Laravel \ChunkUpload \Config \AbstractConfig ;
11
12
use Pion \Laravel \ChunkUpload \Config \FileConfig ;
12
13
use Pion \Laravel \ChunkUpload \Handler \HandlerFactory ;
13
14
use Pion \Laravel \ChunkUpload \Receiver \FileReceiver ;
14
15
use Pion \Laravel \ChunkUpload \Storage \ChunkStorage ;
15
- use Storage ;
16
16
17
17
class ChunkUploadServiceProvider extends ServiceProvider
18
18
{
@@ -22,7 +22,8 @@ class ChunkUploadServiceProvider extends ServiceProvider
22
22
public function boot ()
23
23
{
24
24
// Get the schedule config
25
- $ scheduleConfig = AbstractConfig::config ()->scheduleConfig ();
25
+ $ config = $ this ->app ->make (AbstractConfig::class);
26
+ $ scheduleConfig = $ config ->scheduleConfig ();
26
27
27
28
// Run only if schedule is enabled
28
29
if (true === Arr::get ($ scheduleConfig , 'enabled ' , false )) {
@@ -33,9 +34,12 @@ public function boot()
33
34
$ schedule = $ this ->app ->make (Schedule::class);
34
35
35
36
// Register the clear chunks with custom schedule
36
- $ schedule ->command ('uploads:clear ' )->cron (Arr::get ($ scheduleConfig , 'cron ' , '* * * * * ' ));
37
+ $ schedule ->command ('uploads:clear ' )
38
+ ->cron (Arr::get ($ scheduleConfig , 'cron ' , '* * * * * ' ));
37
39
});
38
40
}
41
+
42
+ $ this ->registerHandlers ($ config ->handlers ());
39
43
}
40
44
41
45
/**
@@ -64,7 +68,7 @@ public function register()
64
68
$ config = $ app ->make (AbstractConfig::class);
65
69
66
70
// Build the chunk storage
67
- return new ChunkStorage (Storage:: disk ($ config ->chunksDiskName ()), $ config );
71
+ return new ChunkStorage ($ this -> disk ($ config ->chunksDiskName ()), $ config );
68
72
});
69
73
70
74
/*
@@ -83,11 +87,25 @@ public function register()
83
87
}
84
88
85
89
/**
86
- * Publishes and mergers the config. Uses the FileConfig.
90
+ * Returns disk name.
91
+ *
92
+ * @param string $diskName
93
+ *
94
+ * @return \Illuminate\Contracts\Filesystem\Filesystem
95
+ */
96
+ protected function disk ($ diskName )
97
+ {
98
+ return Storage::disk ($ diskName );
99
+ }
100
+
101
+ /**
102
+ * Publishes and mergers the config. Uses the FileConfig. Registers custom handlers.
87
103
*
88
104
* @see FileConfig
89
105
* @see ServiceProvider::publishes
90
106
* @see ServiceProvider::mergeConfigFrom
107
+ *
108
+ * @return $this
91
109
*/
92
110
protected function registerConfig ()
93
111
{
@@ -106,5 +124,30 @@ protected function registerConfig()
106
124
$ configPath ,
107
125
$ configIndex
108
126
);
127
+
128
+ return $ this ;
129
+ }
130
+
131
+ /**
132
+ * Registers handlers from config.
133
+ *
134
+ * @param array $handlersConfig
135
+ *
136
+ * @return $this
137
+ */
138
+ protected function registerHandlers (array $ handlersConfig )
139
+ {
140
+ $ overrideHandlers = Arr::get ($ handlersConfig , 'override ' , []);
141
+ if (count ($ overrideHandlers ) > 0 ) {
142
+ HandlerFactory::setHandlers ($ overrideHandlers );
143
+
144
+ return $ this ;
145
+ }
146
+
147
+ foreach (Arr::get ($ handlersConfig , 'custom ' , []) as $ handler ) {
148
+ HandlerFactory::register ($ handler );
149
+ }
150
+
151
+ return $ this ;
109
152
}
110
153
}
0 commit comments