模块创建新增创建table&form文件夹

This commit is contained in:
JaguarJack 2021-04-29 08:48:49 +08:00
parent 6c22fed48d
commit 4abed197aa

View File

@ -5,6 +5,7 @@ namespace catcher\generate;
use catcher\CatchAdmin; use catcher\CatchAdmin;
use catcher\facade\FileSystem; use catcher\facade\FileSystem;
use catcher\library\Composer; use catcher\library\Composer;
use catcher\library\form\FormFactory;
class CreateModule class CreateModule
{ {
@ -77,7 +78,7 @@ class CreateModule
* @time 2020年06月25日 * @time 2020年06月25日
* @return string[] * @return string[]
*/ */
protected function moduleFiles() protected function moduleFiles(): array
{ {
return [ return [
$this->moduleDir . ucfirst($this->module). 'Service.php', $this->moduleDir . ucfirst($this->module). 'Service.php',
@ -103,10 +104,11 @@ class CreateModule
* @time 2020年06月25日 * @time 2020年06月25日
* @return string[] * @return string[]
*/ */
protected function modulePath() protected function modulePath(): array
{ {
$dirs = []; $dirs = [];
foreach (explode(',', $this->dirs) as $dir) { foreach (explode(',', $this->dirs) as $dir) {
if ($dir == 'database') { if ($dir == 'database') {
$dirs[] = $this->moduleDir . 'database' . DIRECTORY_SEPARATOR . 'migrations'; $dirs[] = $this->moduleDir . 'database' . DIRECTORY_SEPARATOR . 'migrations';
@ -117,6 +119,10 @@ class CreateModule
} }
$dirs[] = $this->moduleDir . 'tables';
$dirs[] = $this->moduleDir . 'tables'.DIRECTORY_SEPARATOR.'forms';
return $dirs; return $dirs;
} }
@ -146,6 +152,7 @@ class CreateModule
$this->createService(); $this->createService();
$this->createRoute(); $this->createRoute();
$this->createModuleJson(); $this->createModuleJson();
$this->createFormFactory();
} }
/** /**
@ -202,4 +209,35 @@ class CreateModule
{ {
FileSystem::put($this->moduleDir . 'route.php', FileSystem::sharedGet($this->stubDir . 'route.stub')); FileSystem::put($this->moduleDir . 'route.php', FileSystem::sharedGet($this->stubDir . 'route.stub'));
} }
/**
* create form factory
*
* @time 2021年04月28日
* @return void
*/
protected function createFormFactory()
{
$factoryContent = <<<PHP
<?php
namespace catchAdmin\\{$this->module}\\tables\\forms;
use catcher\\library\\form\\FormFactory;
class Factory extends FormFactory
{
public static function from(): string
{
return __NAMESPACE__;
}
}
PHP;
FileSystem::put($this->moduleDir . 'tables' . DIRECTORY_SEPARATOR . 'forms' . DIRECTORY_SEPARATOR . 'Factory.php',
$factoryContent
);
}
} }