改名
This commit is contained in:
@@ -126,6 +126,29 @@ abstract class GiiBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $fileName
|
||||||
|
* @param ReflectionClass $class
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getImports(string $fileName, ReflectionClass $class): string
|
||||||
|
{
|
||||||
|
$startLine = 1;
|
||||||
|
$array = [];
|
||||||
|
$fileOpen = fopen($fileName, 'r');
|
||||||
|
while (($content = fgets($fileOpen)) !== false) {
|
||||||
|
if (str_starts_with($content, 'use ')) {
|
||||||
|
$array[] = $content;
|
||||||
|
}
|
||||||
|
if ($startLine == $class->getStartLine()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++$startLine;
|
||||||
|
}
|
||||||
|
return implode($array);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $fields
|
* @param $fields
|
||||||
* @return mixed 返回表主键
|
* @return mixed 返回表主键
|
||||||
|
|||||||
+14
-3
@@ -56,9 +56,18 @@ class GiiModel extends GiiBase
|
|||||||
|
|
||||||
if (file_exists($modelPath['path'] . '/' . $managerName . '.php')) {
|
if (file_exists($modelPath['path'] . '/' . $managerName . '.php')) {
|
||||||
try {
|
try {
|
||||||
$class = Snowflake::getDi()->getReflect("{$modelPath['namespace']}\{$managerName}");
|
$className = str_replace('\\\\', '\\', "{$modelPath['namespace']}\\{$managerName}");
|
||||||
|
|
||||||
$html = $this->getUseContent($class, $classFileName);
|
$class = Snowflake::getDi()->getReflect($className);
|
||||||
|
|
||||||
|
$html = '<?php
|
||||||
|
namespace ' . $namespace . ';
|
||||||
|
|
||||||
|
';
|
||||||
|
$imports = $this->getImports($modelPath['path'] . '/' . $managerName . '.php', $class);
|
||||||
|
if (!empty($imports)) {
|
||||||
|
$html .= $imports . PHP_EOL. PHP_EOL;
|
||||||
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
logger()->error($e->getMessage());
|
logger()->error($e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -69,11 +78,13 @@ class GiiModel extends GiiBase
|
|||||||
$html = '<?php
|
$html = '<?php
|
||||||
namespace ' . $namespace . ';
|
namespace ' . $namespace . ';
|
||||||
|
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Annotation\Target;
|
use Annotation\Target;
|
||||||
use Snowflake\Core\JSON;
|
use Snowflake\Core\JSON;
|
||||||
use Database\Connection;
|
use Database\Connection;
|
||||||
use Database\ActiveRecord;';
|
use Database\ActiveRecord;
|
||||||
|
' . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
$createSql = $this->setCreateSql($this->tableName);
|
$createSql = $this->setCreateSql($this->tableName);
|
||||||
|
|||||||
Reference in New Issue
Block a user