From bf30b6615355e872f0800105809439585fef0f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 17 May 2021 17:30:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Events/OnWorkerStart.php | 3 +++ System/Abstracts/Config.php | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/HttpServer/Events/OnWorkerStart.php b/HttpServer/Events/OnWorkerStart.php index 9ae1c889..5a920419 100644 --- a/HttpServer/Events/OnWorkerStart.php +++ b/HttpServer/Events/OnWorkerStart.php @@ -6,6 +6,7 @@ namespace HttpServer\Events; use Annotation\Annotation; use Exception; use HttpServer\Abstracts\Callback; +use Snowflake\Abstracts\Config; use Snowflake\Event; use Snowflake\Exception\ConfigException; use Snowflake\Runtime; @@ -34,6 +35,8 @@ class OnWorkerStart extends Callback putenv('state=start'); putenv('worker=' . $worker_id); + Config::sets(sweep(APP_PATH . 'config')); + $annotation = Snowflake::app()->getAnnotation(); $annotation->setLoader(unserialize(file_get_contents(storage(Runtime::CACHE_NAME)))); if ($worker_id >= $server->setting['worker_num']) { diff --git a/System/Abstracts/Config.php b/System/Abstracts/Config.php index 77fb69cc..7e1087dc 100644 --- a/System/Abstracts/Config.php +++ b/System/Abstracts/Config.php @@ -6,12 +6,11 @@ * Time: 11:50 */ declare(strict_types=1); + namespace Snowflake\Abstracts; use Exception; - use Snowflake\Exception\ConfigException; -use Snowflake\Abstracts\Component; use Snowflake\Snowflake; @@ -46,6 +45,17 @@ class Config extends Component return $this->data[$key] = $value; } + + /** + * @param array $configs + * @throws Exception + */ + public static function sets(array $configs) + { + $config = Snowflake::app()->getConfig(); + $config->data = $configs; + } + /** * @param $key * @param bool $try @@ -69,7 +79,7 @@ class Config extends Component } return $default; } - if (!is_array($instance[$value]) ) { + if (!is_array($instance[$value])) { return $instance[$value]; } $instance = $instance[$value];