Skip to content

Commit 8ae4dad

Browse files
committed
feat: Dynamic loading config
1 parent 1965aba commit 8ae4dad

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/ServiceProvider.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace AlphaSnow\AliyunOss;
44

55
use AlphaSnow\Flysystem\AliyunOss\Plugins\AppendContent;
6+
use Illuminate\Contracts\Foundation\CachesConfiguration;
67
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
78
use League\Flysystem\Config as FlysystemConfig;
89
use 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

Comments
 (0)