webman迁移-优化curd
This commit is contained in:
@@ -424,14 +424,18 @@ class Helper
|
||||
return root_path() . 'app' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'crud' . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . Filesystem::fsFit($name) . '.stub';
|
||||
}
|
||||
|
||||
public static function arrayToString(array|string $value): string
|
||||
public static function arrayToString(mixed $value): string
|
||||
{
|
||||
if (!is_array($value)) return $value;
|
||||
if (is_array($value)) {
|
||||
foreach ($value as &$item) {
|
||||
$item = self::arrayToString($item);
|
||||
}
|
||||
return implode(PHP_EOL, $value);
|
||||
}
|
||||
if (is_string($value)) return $value;
|
||||
if (is_bool($value)) return $value ? 'true' : 'false';
|
||||
return $value === null ? '' : strval($value);
|
||||
}
|
||||
|
||||
public static function assembleStub(string $name, array $data, bool $escape = false): string
|
||||
{
|
||||
|
||||
@@ -11,10 +11,10 @@ class {%className%} extends Backend
|
||||
{
|
||||
/**
|
||||
* {%modelName%}模型对象
|
||||
* @var object
|
||||
* @phpstan-var \{%modelNamespace%}\{%modelName%}
|
||||
* @var object|null
|
||||
* @phpstan-var \{%modelNamespace%}\{%modelName%}|null
|
||||
*/
|
||||
protected object $model;
|
||||
protected ?object $model = null;
|
||||
{%attr%}{%initialize%}
|
||||
{%methods%}
|
||||
|
||||
|
||||
@@ -377,11 +377,16 @@ if (!function_exists('parse_name')) {
|
||||
if (!function_exists('root_path')) {
|
||||
/**
|
||||
* 根路径(BuildAdmin 兼容,等价于 base_path)
|
||||
* 无参数时返回带尾部分隔符的路径,确保 root_path() . 'app' 拼接正确
|
||||
* @param string $path 子路径
|
||||
*/
|
||||
function root_path(string $path = ''): string
|
||||
{
|
||||
return base_path($path);
|
||||
$base = base_path($path);
|
||||
if ($path === '' && $base !== '') {
|
||||
return rtrim($base, DIRECTORY_SEPARATOR . '/') . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
return $base;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -249,8 +249,19 @@ Route::add(
|
||||
if (!method_exists($class, $action)) {
|
||||
return new Response(404, ['Content-Type' => 'application/json'], json_encode(['code' => 404, 'msg' => '404 Not Found', 'data' => []], JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
// 设置 controller 供 get_controller_path、权限校验等使用
|
||||
$request->controller = $class;
|
||||
try {
|
||||
$instance = new $class();
|
||||
return $instance->$action($request);
|
||||
} catch (\Throwable $e) {
|
||||
return new Response(500, ['Content-Type' => 'application/json'], json_encode([
|
||||
'code' => 0,
|
||||
'msg' => $e->getMessage(),
|
||||
'time' => time(),
|
||||
'data' => null,
|
||||
], JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user