22
33namespace AlphaSnow \LaravelFilesystem \Aliyun ;
44
5+ use AlphaSnow \LaravelFilesystem \Aliyun \Macros \AliyunMacro ;
6+ use AlphaSnow \LaravelFilesystem \Aliyun \Macros \AppendFile ;
7+ use AlphaSnow \LaravelFilesystem \Aliyun \Macros \AppendObject ;
58use Illuminate \Support \ServiceProvider as BaseServiceProvider ;
69use Illuminate \Filesystem \FilesystemAdapter ;
710use League \Flysystem \Filesystem ;
811use OSS \OssClient ;
912
1013class AliyunServiceProvider extends BaseServiceProvider
1114{
15+ private $ defaultMacros = [
16+ AppendObject::class,
17+ AppendFile::class,
18+ ];
19+
1220 public function boot ()
1321 {
1422 $ this ->mergeConfigFrom (
@@ -27,9 +35,17 @@ public function boot()
2735 $ aliyunConfig ->get ("timeout " ) && $ ossClient ->setTimeout ($ config ["timeout " ]);
2836 $ aliyunConfig ->get ("connect_timeout " ) && $ ossClient ->setConnectTimeout ($ config ["connect_timeout " ]);
2937
30- $ ossAdapter = new AliyunAdapter ($ ossClient , $ aliyunConfig );
38+ $ aliyunAdapter = new AliyunAdapter ($ ossClient , $ aliyunConfig );
39+ $ filesystemAdapter = new FilesystemAdapter (new Filesystem ($ aliyunAdapter ), $ aliyunAdapter , $ config );
3140
32- return new FilesystemAdapter (new Filesystem ($ ossAdapter ), $ ossAdapter , $ config );
41+ $ macros = array_merge ($ this ->defaultMacros , $ aliyunConfig ->get ('macros ' , []));
42+ foreach ($ macros as $ macro ) {
43+ $ aliyunMacro = $ app ->make ($ macro );
44+ if ($ aliyunMacro instanceof AliyunMacro) {
45+ $ filesystemAdapter ::macro ($ aliyunMacro ->name (), $ aliyunMacro ->macro ());
46+ }
47+ }
48+ return $ filesystemAdapter ;
3349 });
3450 }
3551}
0 commit comments