From ae77f59c55771b45606782e411bec8f537404ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 1 Apr 2021 15:57:15 +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/GiiController.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Gii/GiiController.php b/Gii/GiiController.php index 89a34ff7..70837fed 100644 --- a/Gii/GiiController.php +++ b/Gii/GiiController.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Gii; use Exception; +use ReflectionException; use Snowflake\Snowflake; /** @@ -18,6 +19,12 @@ class GiiController extends GiiBase public array $fields = []; + + /** + * GiiController constructor. + * @param $className + * @param $fields + */ public function __construct($className, $fields) { $this->className = $className; @@ -27,7 +34,8 @@ class GiiController extends GiiBase /** * @return string|bool - * @throws \ReflectionException + * @throws ReflectionException + * @throws Exception */ public function generate(): string|bool { @@ -375,16 +383,11 @@ use {$model_namespace}\\{$managerName}; $_field['type'] = $_key; if ($type == 'date' || $type == 'datetime' || $type == 'time') { - switch ($type) { - case 'date': - $_tps = '$this->input->' . $_key . '(\'' . $val['Field'] . '\', date(\'Y-m-d\'))'; - break; - case 'time': - $_tps = '$this->input->' . $_key . '(\'' . $val['Field'] . '\', date(\'H:i:s\'))'; - break; - default: - $_tps = '$this->input->' . $_key . '(\'' . $val['Field'] . '\', date(\'Y-m-d H:i:s\'))'; - } + $_tps = match ($type) { + 'date' => '$this->input->' . $_key . '(\'' . $val['Field'] . '\', date(\'Y-m-d\'))', + 'time' => '$this->input->' . $_key . '(\'' . $val['Field'] . '\', date(\'H:i:s\'))', + default => '$this->input->' . $_key . '(\'' . $val['Field'] . '\', date(\'Y-m-d H:i:s\'))', + }; $html .= ' \'' . str_pad($val['Field'] . '\'', $length, ' ', STR_PAD_RIGHT) . ' => ' . str_pad($_tps . ',', 60, ' ', STR_PAD_RIGHT) . $comment; } else {