This commit is contained in:
2021-03-25 18:28:41 +08:00
parent e89ce9f2f1
commit 823c1ded50
4 changed files with 140 additions and 103 deletions
+94 -1
View File
@@ -6,9 +6,11 @@ namespace Gii;
use Database\Connection;
use Exception;
use JetBrains\PhpStorm\ArrayShape;
use ReflectionClass;
use ReflectionException;
use Snowflake\Abstracts\Input;
/**
@@ -149,6 +151,97 @@ abstract class GiiBase
}
/**
* @param ReflectionClass $class
* @return string
* @throws ReflectionException
*/
protected function getClassProperty(ReflectionClass $class): string
{
$html = '';
foreach ($class->getConstants() as $key => $val) {
if (is_numeric($val)) {
$html .= '
const ' . $key . ' = ' . $val . ';' . "\n";
} else {
$html .= '
const ' . $key . ' = \'' . $val . '\';' . "\n";
}
}
foreach ($class->getDefaultProperties() as $key => $val) {
$property = $class->getProperty($key);
if ($property->class != $class->getName()) continue;
if (is_array($val)) {
$val = '[\'' . implode('\', \'', $val) . '\']';
} else if (!is_numeric($val)) {
$val = '\'' . $val . '\'';
}
if ($property->isProtected()) {
$debug = 'protected';
} else if ($property->isPrivate()) {
$debug = 'private';
} else {
$debug = 'public';
}
if ($property->hasType()) {
$type = ' ' . $property->getType() . ' $' . $key . ' = ' . $val . ';' . "\n";
} else {
$type = ' $' . $key . ' = ' . $val . ';' . "\n";
}
if ($property->isStatic()) {
$html .= '
' . $debug . ' static' . $type;
} else {
if ($key == 'primary') {
continue;
}
$html .= '
' . $debug . $type;
}
}
return $html;
}
/**
* @param ReflectionClass $class
* @param array $filters
* @return string
* @throws Exception
*/
protected function getClassMethods(ReflectionClass $class, array $filters = []): string
{
$methods = $class->getMethods();
$classFileName = str_replace(APP_PATH, '', $class->getFileName());
$content = [];
if (!empty($methods)) foreach ($methods as $key => $val) {
if ($val->class != $class->getName()) continue;
if (in_array($val->name, $filters)) continue;
$over = "
" . $val->getDocComment() . "\n";
$attributes = $val->getAttributes();
if (!empty($attributes)) {
foreach ($attributes as $attribute) {
$explode = explode('\\', $attribute->getName());
$over .= " #[" . end($explode) . "('" . implode('\',\'', $attribute->getArguments()) . "')]
";
}
}
$func = $this->getFuncLineContent($class, $classFileName, $val->name) . "\n";
$content[] = $over . $func;
}
return implode($content);
}
/**
* @param $fields
* @return mixed 返回表主键
@@ -189,7 +282,7 @@ abstract class GiiBase
* @param $className
* @param $method
* @return string
* @throws \Exception
* @throws Exception
*/
public function getFuncLineContent(ReflectionClass $object, $className, $method): string
{