From aba55464299749cb9ccbc1a87f199d91114b5c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 25 Mar 2021 19:36:00 +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/GiiBase.php | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/Gii/GiiBase.php b/Gii/GiiBase.php index 3b165a66..13ffb77b 100644 --- a/Gii/GiiBase.php +++ b/Gii/GiiBase.php @@ -12,6 +12,7 @@ use JetBrains\PhpStorm\ArrayShape; use ReflectionClass; use ReflectionException; use Snowflake\Abstracts\Input; +use Snowflake\Core\Json; /** * Class GiiBase @@ -229,7 +230,48 @@ abstract class GiiBase if (!empty($attributes)) { foreach ($attributes as $attribute) { $explode = explode('\\', $attribute->getName()); - $over .= " #[" . end($explode) . "('" . implode('\',\'', $attribute->getArguments()) . "')] + + $_array = []; + foreach ($attribute->getArguments() as $_key => $argument) { + if (is_numeric($_key)) { + $_array[] = '\'' . $argument . '\''; + } else { + if (is_array($argument)) { + $__array = []; + foreach ($argument as $key => $value) { + if (is_string($value)) { + if (str_contains($value, '\\') && class_exists($value)) { + $explode_class = explode('\\', $value); + + $__array[] = end($explode_class) . '::class'; + } else { + $__array[] = '\'' . $value . '\''; + } + } else { + $value = str_replace('{', '[', Json::encode($value)); + $value = str_replace('}', ']', Json::encode($value)); + $value = str_replace(':', '=>', Json::encode($value)); + + $value = preg_replace('/"\d+"\=\>/', '', $value); + + $__array[] = $value; + } + } + + $argument = '[' . implode(', ', $__array) . ']'; + } else { + $argument = '\'' . $argument . '\''; + } + + if (is_numeric($_key)) { + $_array[] = $argument; + } else { + $_array[] = $_key . ': ' . $argument . ''; + } + + } + } + $over .= " #[" . end($explode) . "(" . implode(',', $_array) . ")] "; } } @@ -238,7 +280,6 @@ abstract class GiiBase $content[] = $over . $func; } - return implode($content); }