代码生成器
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
<?php
|
||||
namespace JaguarJack\Generator;
|
||||
namespace catcher\generate;
|
||||
|
||||
use catcher\CatchAdmin;
|
||||
use JaguarJack\Generator\Factory\Controller;
|
||||
use JaguarJack\Generator\Factory\SQl;
|
||||
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\generate\factory\Controller;
|
||||
use catcher\generate\factory\Migration;
|
||||
use catcher\generate\factory\Model;
|
||||
use catcher\generate\factory\SQL;
|
||||
|
||||
class Generator
|
||||
{
|
||||
@@ -11,15 +14,73 @@ class Generator
|
||||
{
|
||||
$params = \json_decode($params['data'], true);
|
||||
|
||||
//var_dump((new Controller())->generate($params['controller']));die;
|
||||
[$controller, $model] = $this->parseParams($params);
|
||||
|
||||
(new Controller())->done($params['controller']);
|
||||
$message = [];
|
||||
if ($params['create_controller']) {
|
||||
if ((new Controller)->done($controller)) {
|
||||
array_push($message, 'controller created successfully');
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['create_table']) {
|
||||
if ((new SQL)->done($model)) {
|
||||
array_push($message, 'table created successfully');
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['create_model']) {
|
||||
if ((new Model)->done($model)) {
|
||||
array_push($message, 'model created successfully');
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['create_migration']) {
|
||||
if ((new Migration)->done([$controller['module'], $model['table']])) {
|
||||
array_push($message, 'migration created successfully');
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function preview($type, $params)
|
||||
{
|
||||
$class = ucfirst($type);
|
||||
|
||||
(new $class)->done();
|
||||
(new $class)->done($params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* parse params
|
||||
*
|
||||
* @time 2020年04月28日
|
||||
* @param $params
|
||||
* @return array[]
|
||||
*/
|
||||
protected function parseParams($params)
|
||||
{
|
||||
if (!$params['controller']['module'] ?? false) {
|
||||
throw new FailedException('请设置模块');
|
||||
}
|
||||
|
||||
$controller = [
|
||||
'module' => $params['controller']['module'],
|
||||
'model' => $params['controller']['model'] ?? '',
|
||||
'controller' => $params['controller']['controller'] ?? '',
|
||||
'restful' => $params['controller']['restful'],
|
||||
'other_function' => $params['controller']['other_function'],
|
||||
];
|
||||
|
||||
$model = [
|
||||
'table' => $params['controller']['table'],
|
||||
'model' => $params['controller']['model'],
|
||||
'sql' => $params['model']['data'],
|
||||
'extra' => $params['model']['extra'],
|
||||
];
|
||||
|
||||
|
||||
return [$controller, $model];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user