From 0b3b27c7a37188235ff64f76ff922eae878d44d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 6 Apr 2021 18:28:30 +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 | 65 ++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/Gii/GiiBase.php b/Gii/GiiBase.php index c09f5cec..de545419 100644 --- a/Gii/GiiBase.php +++ b/Gii/GiiBase.php @@ -239,42 +239,15 @@ abstract class GiiBase $_array = []; foreach ($attribute->getArguments() as $_key => $argument) { + $argument = $this->resolveArray($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) . ")] @@ -290,6 +263,42 @@ abstract class GiiBase } + /** + * @param $argument + * @return string + */ + private function resolveArray($argument): string + { + 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 . '\''; + } + return $argument; + } + + /** * @param $fields * @return mixed 返回表主键