生成代码新增回滚功能

This commit is contained in:
JaguarJack
2020-07-11 10:59:57 +08:00
parent 42e75f50ff
commit 359381fec6
6 changed files with 68 additions and 22 deletions

View File

@@ -18,11 +18,9 @@ class Controller extends Factory
public function done($params)
{
// 写入成功之后
if (file_put_contents($this->getGeneratePath($params['controller']), $this->getContent($params))) {
return (new Route())->controller($params['controller'])
->restful($params['restful'])
->methods($this->parseOtherMethods($params['other_function']))
->done();
$controllerPath = $this->getGeneratePath($params['controller']);
if (file_put_contents($controllerPath, $this->getContent($params))) {
return $controllerPath;
}
throw new FailedException($params['controller'] . ' generate failed~');

View File

@@ -89,7 +89,7 @@ abstract class Factory
* @param $table
* @return bool
*/
protected function hasTableExists($table)
public function hasTableExists($table)
{
$tables = Db::getConnection()->getTables();

View File

@@ -48,6 +48,6 @@ class Migration extends Factory
}
}
return true;
return $file;
}
}

View File

@@ -12,13 +12,15 @@ class Model extends Factory
{
$content = $this->getContent($params);
file_put_contents($this->getGeneratePath($params['model']), $content);
$modelPath = $this->getGeneratePath($params['model']);
if (!file_exists($this->getGeneratePath($params['model']))) {
file_put_contents($modelPath, $content);
if (!file_exists($modelPath)) {
throw new FailedException('create model failed');
}
return true;
return $modelPath;
}
/**

View File

@@ -19,7 +19,7 @@ class SQL extends Factory
throw new FailedException(sprintf('create table [%s] failed', $params['table']));
}
return true;
return $params['table'];
}
/**