33namespace AlphaSnow \AliyunOss ;
44
55use AlphaSnow \Flysystem \AliyunOss \Plugins \AppendContent ;
6+ use Illuminate \Contracts \Foundation \CachesConfiguration ;
67use Illuminate \Support \ServiceProvider as BaseServiceProvider ;
78use League \Flysystem \Config as FlysystemConfig ;
89use League \Flysystem \Filesystem ;
@@ -19,11 +20,6 @@ class ServiceProvider extends BaseServiceProvider
1920 */
2021 public function boot ()
2122 {
22- $ this ->mergeConfigFrom (
23- __DIR__ .'/config/config.php ' ,
24- 'filesystems.disks.aliyun '
25- );
26-
2723 $ this ->app ->make ('filesystem ' )
2824 ->extend ('aliyun ' , function ($ app , array $ config ) {
2925 return $ app ->make ('aliyun-oss.oss-filesystem ' , $ config );
@@ -35,6 +31,8 @@ public function boot()
3531 */
3632 public function register ()
3733 {
34+ $ this ->registerConfig ();
35+
3836 $ this ->app ->bind ('aliyun-oss.oss-client ' , function ($ app , array $ config ) {
3937 $ ossConfig = new Config ($ config );
4038
@@ -43,7 +41,6 @@ public function register()
4341 return $ client ;
4442 });
4543
46-
4744 $ this ->app ->bind ('aliyun-oss.oss-adapter ' , function ($ app , array $ config ) {
4845 $ client = $ app ->make ('aliyun-oss.oss-client ' , $ config );
4946
@@ -58,4 +55,23 @@ public function register()
5855 return $ filesystem ;
5956 });
6057 }
58+
59+ protected function registerConfig ()
60+ {
61+ if ($ this ->app instanceof CachesConfiguration && $ this ->app ->configurationIsCached ()) {
62+ return ;
63+ }
64+
65+ $ config = $ this ->app ->make ('config ' );
66+ $ disks = $ config ->get ("filesystems.disks " , []);
67+ $ drivers = array_column ($ disks , "driver " );
68+ if (in_array ("aliyun " , $ drivers )) {
69+ return ;
70+ }
71+
72+ $ config ->set ("filesystems.disks.aliyun " , array_merge (
73+ require __DIR__ . "/config/config.php " ,
74+ $ config ->get ("filesystems.disks.aliyun " , [])
75+ ));
76+ }
6177}
0 commit comments