用户管理
This commit is contained in:
17
extend/think-module/src/ThinkModuleService.php
Normal file
17
extend/think-module/src/ThinkModuleService.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace jaguarjack\think\module;
|
||||
|
||||
use jaguarjack\think\module\command\CreateModuleCommand;
|
||||
use jaguarjack\think\module\command\DiscoverModuleServiceCommand;
|
||||
use think\Service;
|
||||
|
||||
class ThinkModuleService extends Service
|
||||
{
|
||||
public function boot()
|
||||
{
|
||||
$this->commands([
|
||||
CreateModuleCommand::class,
|
||||
DiscoverModuleServiceCommand::class,
|
||||
]);
|
||||
}
|
||||
}
|
131
extend/think-module/src/command/CreateModuleCommand.php
Normal file
131
extend/think-module/src/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')));
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
namespace jaguarjack\think\module\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
|
||||
class DiscoverModuleServiceCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('module:service')
|
||||
->setDescription('discover module service');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$this->getModuleServices();
|
||||
|
||||
$output->writeln('module service generator succeed!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模块
|
||||
*
|
||||
* @time 2019年11月27日
|
||||
* @return bool
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected function getModuleServices(): bool
|
||||
{
|
||||
$modules = glob(root_path('module') .'*');
|
||||
$moduleServices = [];
|
||||
|
||||
foreach ($modules as $module) {
|
||||
if (file_exists($module . DIRECTORY_SEPARATOR . 'module.json')) {
|
||||
$moduleJson = file_get_contents($module . DIRECTORY_SEPARATOR . 'module.json');
|
||||
$moduleServices = array_merge($moduleServices, \json_decode($moduleJson, true)['services']);
|
||||
}
|
||||
}
|
||||
|
||||
$moduleServices = $this->checkModuleService($moduleServices);
|
||||
|
||||
$header = '// This file is automatically generated at:' . date('Y-m-d H:i:s') . PHP_EOL . 'declare (strict_types = 1);' . PHP_EOL;
|
||||
|
||||
$content =
|
||||
'<?php ' . PHP_EOL . $header . 'return ' .
|
||||
|
||||
var_export($moduleServices, true) . ';';
|
||||
|
||||
file_put_contents($this->app->getRootPath() . 'module/services.php', $content);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年11月29日
|
||||
* @param $moduleServices
|
||||
* @throws \ReflectionException
|
||||
* @return mixed
|
||||
*/
|
||||
protected function checkModuleService($moduleServices)
|
||||
{
|
||||
$new = [];
|
||||
|
||||
foreach ($moduleServices as $key => $service) {
|
||||
$selfReflection = new \ReflectionClass($service);
|
||||
// if service set property 'cache' && set cache => false
|
||||
// the service will not be cached
|
||||
// finally will boot it
|
||||
if ($selfReflection->hasProperty('cache') && !$selfReflection->getProperty('cache')) {
|
||||
$new[$service] = true;
|
||||
} else {
|
||||
$new[$service] = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $new;
|
||||
}
|
||||
}
|
21
extend/think-module/src/command/stubs/command.stub
Normal file
21
extend/think-module/src/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)
|
||||
{
|
||||
}
|
||||
}
|
25
extend/think-module/src/command/stubs/composer.stub
Normal file
25
extend/think-module/src/command/stubs/composer.stub
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "$VENDOR$/$LOWER_NAME$",
|
||||
"description": "",
|
||||
"authors": [
|
||||
{
|
||||
"name": "$AUTHOR_NAME$",
|
||||
"email": "$AUTHOR_EMAIL$"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\$PROVIDER_NAMESPACE$\\$STUDLY_NAME$ServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\": ""
|
||||
}
|
||||
}
|
||||
}
|
35
extend/think-module/src/command/stubs/controller.stub
Normal file
35
extend/think-module/src/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/think-module/src/command/stubs/event.stub
Normal file
11
extend/think-module/src/command/stubs/event.stub
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace {NAMESPACE};
|
||||
|
||||
class {CLASS}
|
||||
{
|
||||
public function handle()
|
||||
{
|
||||
}
|
||||
}
|
33
extend/think-module/src/command/stubs/migration.stub
Normal file
33
extend/think-module/src/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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
10
extend/think-module/src/command/stubs/model.stub
Normal file
10
extend/think-module/src/command/stubs/model.stub
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace {NAMESPACE};
|
||||
|
||||
use think\Model;
|
||||
|
||||
class {CLASS} extends Model
|
||||
{
|
||||
protected $fillable = $FILLABLE$;
|
||||
}
|
13
extend/think-module/src/command/stubs/module.stub
Normal file
13
extend/think-module/src/command/stubs/module.stub
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "",
|
||||
"alias": "{MODULE}",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"order": 0,
|
||||
"services": [
|
||||
"{SERVICE}"
|
||||
],
|
||||
"aliases": {},
|
||||
"files": [],
|
||||
"requires": []
|
||||
}
|
23
extend/think-module/src/command/stubs/provider.stub
Normal file
23
extend/think-module/src/command/stubs/provider.stub
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace {NAMESPACE};
|
||||
|
||||
use think\Service;
|
||||
|
||||
class {CLASS}Service extends Service
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->loadRoutesFrom(__DIR__ . DIRECTORY_SEPARATOR . 'route.php');
|
||||
|
||||
$this->loadViewFrom();
|
||||
}
|
||||
|
||||
protected function loadViewFrom(): void
|
||||
{
|
||||
moduleViewPathManager()->set('login', __DIR__ . DIRECTORY_SEPARATOR . 'view' .DIRECTORY_SEPARATOR);
|
||||
}
|
||||
}
|
17
extend/think-module/src/command/stubs/request.stub
Normal file
17
extend/think-module/src/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/think-module/src/command/stubs/route.stub
Normal file
5
extend/think-module/src/command/stubs/route.stub
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
// you should user `$router`
|
||||
// $router->get('index', 'controller@method');
|
||||
|
19
extend/think-module/src/command/stubs/seeder.stub
Normal file
19
extend/think-module/src/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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
extend/think-module/src/command/stubs/validate.stub
Normal file
11
extend/think-module/src/command/stubs/validate.stub
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace {Namespace};
|
||||
|
||||
use catcher\base\BaseValidate;
|
||||
|
||||
class {Class}Validate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
// todo your rules
|
||||
];
|
||||
}
|
Reference in New Issue
Block a user