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 返回表主键