添加初始化账号
This commit is contained in:
parent
3d8b31b2dc
commit
57f6597e77
131
extend/catcher/command/CreateModuleCommand.php
Normal file
131
extend/catcher/command/CreateModuleCommand.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
namespace jaguarjack\think\module\command;
|
||||
|
||||
use catcher\CatchAdmin;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\Output;
|
||||
|
||||
class CreateModuleCommand extends Command
|
||||
{
|
||||
protected $module;
|
||||
|
||||
protected $moduleDir;
|
||||
|
||||
protected $namespaces;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('module:create')
|
||||
->addArgument('module', Argument::REQUIRED, 'module name')
|
||||
->setDescription('create module service');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$this->module = strtolower($input->getArgument('module'));
|
||||
|
||||
$this->moduleDir = CatchAdmin::moduleDirectory($this->module);
|
||||
|
||||
$this->namespaces = CatchAdmin::NAME . '\\\\' . $this->module . '\\\\';
|
||||
|
||||
$this->createController();
|
||||
$this->createRequest();
|
||||
$this->createModel();
|
||||
// $this->createService();
|
||||
$this->createView();
|
||||
$this->createValidate();
|
||||
$this->createRoute();
|
||||
$this->moduleJson();
|
||||
|
||||
$output->warning('module created');
|
||||
}
|
||||
|
||||
|
||||
protected function createController()
|
||||
{
|
||||
mkdir($this->moduleDir . 'controller' . DIRECTORY_SEPARATOR);
|
||||
return file_put_contents($this->moduleDir . 'controller' . DIRECTORY_SEPARATOR . 'Index.php', str_replace(
|
||||
['{CLASS}', '{NAMESPACE}', '{MODULE}'],
|
||||
['Index', $this->namespaces . 'controller', $this->module],
|
||||
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR .'stubs'.DIRECTORY_SEPARATOR. 'controller.stub')
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
protected function createModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function createView()
|
||||
{
|
||||
mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'view');
|
||||
|
||||
file_put_contents($this->moduleDir . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'index.html', '');
|
||||
file_put_contents($this->moduleDir . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'create.html', '');
|
||||
file_put_contents($this->moduleDir . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'edit.html', '');
|
||||
}
|
||||
|
||||
protected function createValidate()
|
||||
{
|
||||
$validatePath = $this->moduleDir . DIRECTORY_SEPARATOR . 'validate' . DIRECTORY_SEPARATOR;
|
||||
mkdir($validatePath);
|
||||
file_put_contents($validatePath . 'CreateValidate.php', str_replace(
|
||||
['{Namespace}', '{Class}'],
|
||||
[$this->namespaces . 'validate', 'Create'],
|
||||
file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'validate.stub')));
|
||||
|
||||
file_put_contents($validatePath . 'UpdateValidate.php', str_replace(
|
||||
['{Namespace}', '{Class}'],
|
||||
[$this->namespaces . 'validate', 'Update'],
|
||||
file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'validate.stub')));
|
||||
}
|
||||
|
||||
protected function createRequest()
|
||||
{
|
||||
$requestPath = $this->moduleDir . DIRECTORY_SEPARATOR . 'request' . DIRECTORY_SEPARATOR;
|
||||
mkdir($requestPath);
|
||||
file_put_contents($validatePath . 'CreateRequest.php', str_replace(
|
||||
['{Namespace}', '{Class}'],
|
||||
[$this->namespaces . 'request', 'Create'],
|
||||
file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'request.stub')));
|
||||
|
||||
file_put_contents($validatePath . 'UpdateRequest.php', str_replace(
|
||||
['{Namespace}', '{Class}'],
|
||||
[$this->namespaces . 'request', 'Update'],
|
||||
file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'request.stub')));
|
||||
}
|
||||
|
||||
protected function database()
|
||||
{
|
||||
mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'database');
|
||||
mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'database'.DIRECTORY_SEPARATOR.'migrations');
|
||||
mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'database'.DIRECTORY_SEPARATOR . 'seeds');
|
||||
}
|
||||
|
||||
protected function moduleJson()
|
||||
{
|
||||
file_put_contents($this->moduleDir.DIRECTORY_SEPARATOR .'module.json', str_replace(
|
||||
['{MODULE}', '{SERVICE}'],
|
||||
[$this->module, $this->namespaces. ucfirst($this->module) . 'Service'],
|
||||
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'module.stub')));
|
||||
}
|
||||
|
||||
protected function createRoute()
|
||||
{
|
||||
file_put_contents($this->moduleDir.DIRECTORY_SEPARATOR .'route.php',
|
||||
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'route.stub'));
|
||||
}
|
||||
|
||||
protected function createService()
|
||||
{
|
||||
file_put_contents($this->moduleDir.DIRECTORY_SEPARATOR . ucfirst($this->module) . 'Service.php', str_replace(
|
||||
['{CLASS}', '{NAMESPACE}'],
|
||||
[ucfirst($this->module), $this->namespaces . '\\' . $this->module],
|
||||
file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'provider.stub')));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -317,7 +317,8 @@ class InstallCommand extends Command
|
||||
| \___/\__,_/\__/\___/_/ /_/ /_/ |_\__,_/_/ /_/ /_/_/_/ /_/ |
|
||||
| |
|
||||
\ __ __ __ __ _ __ _ __ enjoy it ! _ __ __ __ __ __ __ ___ _ @ 2017 ~ %s
|
||||
|
||||
账号: admin@gmail.com
|
||||
密码: admin
|
||||
', $year));
|
||||
|
||||
}
|
||||
|
21
extend/catcher/command/stubs/command.stub
Normal file
21
extend/catcher/command/stubs/command.stub
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace {NAMESPACE};
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
|
||||
class {CLASS}Command extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('')
|
||||
->setDescription('');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
}
|
||||
}
|
35
extend/catcher/command/stubs/controller.stub
Normal file
35
extend/catcher/command/stubs/controller.stub
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace {NAMESPACE};
|
||||
|
||||
use app\BaseController;
|
||||
|
||||
class {CLASS} extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch('{MODULE}::index');
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return $this->fetch('{MODULE}::create');
|
||||
}
|
||||
|
||||
public function save()
|
||||
{}
|
||||
|
||||
public function read()
|
||||
{}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
return $this->fetch('{MODULE}::edit');
|
||||
}
|
||||
|
||||
public function update()
|
||||
{}
|
||||
|
||||
public function delete()
|
||||
{}
|
||||
|
||||
}
|
11
extend/catcher/command/stubs/event.stub
Normal file
11
extend/catcher/command/stubs/event.stub
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace {NAMESPACE};
|
||||
|
||||
class {CLASS}
|
||||
{
|
||||
public function handle()
|
||||
{
|
||||
}
|
||||
}
|
33
extend/catcher/command/stubs/migration.stub
Normal file
33
extend/catcher/command/stubs/migration.stub
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
|
||||
class {CLASS} extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
13
extend/catcher/command/stubs/module.stub
Normal file
13
extend/catcher/command/stubs/module.stub
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "",
|
||||
"alias": "{MODULE}",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"order": 0,
|
||||
"services": [
|
||||
"{SERVICE}"
|
||||
],
|
||||
"aliases": {},
|
||||
"files": [],
|
||||
"requires": []
|
||||
}
|
17
extend/catcher/command/stubs/request.stub
Normal file
17
extend/catcher/command/stubs/request.stub
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace {NAMESPACE};
|
||||
|
||||
use catcher\base\BaseRequest;
|
||||
|
||||
class {CLASS}Request extends BaseRequest
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @time 2019年11月27日
|
||||
* @return string
|
||||
*/
|
||||
protected function getValidate()
|
||||
{
|
||||
// TODO: Implement getValidate() method.
|
||||
}
|
||||
}
|
5
extend/catcher/command/stubs/route.stub
Normal file
5
extend/catcher/command/stubs/route.stub
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
// you should user `$router`
|
||||
// $router->get('index', 'controller@method');
|
||||
|
19
extend/catcher/command/stubs/seeder.stub
Normal file
19
extend/catcher/command/stubs/seeder.stub
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use think\migration\Seeder;
|
||||
|
||||
class {CLASS} extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run Method.
|
||||
*
|
||||
* Write your database seeder using this method.
|
||||
*
|
||||
* More information on writing seeders is available here:
|
||||
* http://docs.phinx.org/en/latest/seeding.html
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
15
extend/catcher/command/stubs/service.stub
Normal file
15
extend/catcher/command/stubs/service.stub
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace {NAMESPACE};
|
||||
|
||||
use think\Service;
|
||||
|
||||
class {CLASS}Service extends Service
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user