diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01a4aac --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.cache +*.log +.buildpath +.settings/ +.project +*.patch +.idea +.DS_Store +vendor/ +composer.lock \ No newline at end of file diff --git a/composer.json b/composer.json index 32cbeda..aa0000d 100644 --- a/composer.json +++ b/composer.json @@ -12,5 +12,9 @@ "email": "zyimm@qq.com" } ], - "require": {} + "require": { + "hyperf/event": "^2.2", + "hyperf/framework": "^2.2", + "vlucas/phpdotenv": "^5.4" + } } diff --git a/src/Config.php b/src/Config.php new file mode 100644 index 0000000..128aafa --- /dev/null +++ b/src/Config.php @@ -0,0 +1,32 @@ +env = $env; + } + + public function get() + { + // Load env before config. + if (file_exists(BASE_PATH . '/.env.' . $this->env)) { + $repository = RepositoryBuilder::createWithNoAdapters() + ->addReader(Adapter\PutenvAdapter::class) + ->addWriter(Adapter\PutenvAdapter::class) + ->make(); + + Dotenv::create($repository, [BASE_PATH], '.env.' . $this->env)->load(); + } + } +} \ No newline at end of file diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php new file mode 100644 index 0000000..938fe8a --- /dev/null +++ b/src/ConfigProvider.php @@ -0,0 +1,35 @@ + [ + ], + 'commands' => [ + ], + 'listener' => [ + MultiEnvListener::class, + ], + 'annotations' => [ + 'scan' => [ + 'paths' => [ + __DIR__, + ], + 'ignore_annotations' => [ + 'mixin', + ], + ], + ], + 'publish' => [ + ] + ]; + } +} \ No newline at end of file diff --git a/src/Listener/MultiEnvListener.php b/src/Listener/MultiEnvListener.php new file mode 100644 index 0000000..ef9edff --- /dev/null +++ b/src/Listener/MultiEnvListener.php @@ -0,0 +1,44 @@ +get(Config::class); + } + } + } +} \ No newline at end of file