From 58c3705910b76e07f43024ba23558963d781db49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 19 Jan 2021 18:58:09 +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 --- Gii/Gii.php | 26 +++++++++++++++++++++++++- System/Abstracts/Input.php | 10 ++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Gii/Gii.php b/Gii/Gii.php index 5b5f353d..222da4ca 100644 --- a/Gii/Gii.php +++ b/Gii/Gii.php @@ -14,6 +14,7 @@ use Database\Db; use Exception; use JetBrains\PhpStorm\ArrayShape; +use Snowflake\Abstracts\Config; use Snowflake\Abstracts\Input; use Snowflake\Exception\ComponentException; use Snowflake\Exception\ConfigException; @@ -110,10 +111,33 @@ class Gii */ private function getModel($make, $input): array { - if (!$this->db) { + if ($this->db) { + return $this->makeByDatabases($make, $input); + } + if ($this->input->exists('databases')) { $db = $this->input->get('databases', 'db'); $this->db = Snowflake::app()->db->get($db); + + return $this->makeByDatabases($make, $input); } + $array = []; + foreach (Config::get('databases') as $key => $connection) { + $this->db = Snowflake::app()->db->get($key); + + $array[$key] = $this->makeByDatabases($make, $input); + } + return $array; + } + + + /** + * @param $make + * @param $input + * @return array + * @throws ComponentException + */ + private function makeByDatabases($make, $input): array + { $redis = Snowflake::app()->getRedis(); if (!empty($input->get('table'))) { $this->tableName = $input->get('table'); diff --git a/System/Abstracts/Input.php b/System/Abstracts/Input.php index 4f973a11..bd595e56 100644 --- a/System/Abstracts/Input.php +++ b/System/Abstracts/Input.php @@ -45,6 +45,16 @@ class Input return $this->_argv[$key] ?? $default; } + + /** + * @param $key + * @return bool + */ + public function exists($key): bool + { + return isset($this->_argv[$key]); + } + /** * @param $key * @param $value