2019-12-02 23:04:43 +08:00
|
|
|
<?php
|
2020-02-20 13:44:54 +08:00
|
|
|
namespace catcher;
|
2019-12-02 23:04:43 +08:00
|
|
|
|
2019-12-13 17:25:22 +08:00
|
|
|
use catcher\command\BackupCommand;
|
2019-12-17 09:02:29 +08:00
|
|
|
use catcher\command\CompressPackageCommand;
|
2019-12-19 07:18:18 +08:00
|
|
|
use catcher\command\CreateModuleCommand;
|
2020-02-26 11:47:27 +08:00
|
|
|
use catcher\command\install\InstallProjectCommand;
|
2020-01-21 17:00:45 +08:00
|
|
|
use catcher\command\MigrateCreateCommand;
|
|
|
|
use catcher\command\MigrateRollbackCommand;
|
2019-12-03 21:43:37 +08:00
|
|
|
use catcher\command\MigrateRunCommand;
|
|
|
|
use catcher\command\ModelGeneratorCommand;
|
2019-12-02 23:04:43 +08:00
|
|
|
use catcher\command\ModuleCacheCommand;
|
2019-12-10 14:03:28 +08:00
|
|
|
use catcher\command\SeedRunCommand;
|
2020-01-24 08:40:04 +08:00
|
|
|
use catcher\command\worker\WsWorkerCommand;
|
2020-02-02 22:10:52 +08:00
|
|
|
use think\exception\Handle;
|
2019-12-07 17:31:38 +08:00
|
|
|
use think\facade\Validate;
|
2019-12-02 23:04:43 +08:00
|
|
|
use think\Service;
|
|
|
|
|
|
|
|
class CatchAdminService extends Service
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @time 2019年11月29日
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
2020-02-01 15:42:13 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* register
|
|
|
|
*
|
|
|
|
* @author JaguarJack
|
|
|
|
* @email njphper@gmail.com
|
|
|
|
* @time 2020/1/30
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
2019-12-02 23:04:43 +08:00
|
|
|
{
|
2019-12-13 17:25:22 +08:00
|
|
|
$this->registerCommands();
|
2019-12-07 17:31:38 +08:00
|
|
|
$this->registerValidates();
|
2019-12-12 18:53:10 +08:00
|
|
|
$this->registerMiddleWares();
|
2020-04-17 06:48:14 +08:00
|
|
|
$this->registerEvents();
|
2020-01-13 16:23:08 +08:00
|
|
|
$this->registerQuery();
|
2020-02-02 22:10:52 +08:00
|
|
|
$this->registerExceptionHandle();
|
2019-12-07 17:31:38 +08:00
|
|
|
}
|
|
|
|
|
2019-12-13 17:25:22 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @time 2019年12月13日
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function registerCommands(): void
|
|
|
|
{
|
|
|
|
$this->commands([
|
2020-02-26 11:47:27 +08:00
|
|
|
InstallProjectCommand::class,
|
2019-12-13 17:25:22 +08:00
|
|
|
ModuleCacheCommand::class,
|
|
|
|
MigrateRunCommand::class,
|
|
|
|
ModelGeneratorCommand::class,
|
|
|
|
SeedRunCommand::class,
|
|
|
|
BackupCommand::class,
|
2019-12-19 07:18:18 +08:00
|
|
|
CompressPackageCommand::class,
|
|
|
|
CreateModuleCommand::class,
|
2020-01-21 17:00:45 +08:00
|
|
|
MigrateRollbackCommand::class,
|
|
|
|
MigrateCreateCommand::class,
|
2020-01-24 08:40:04 +08:00
|
|
|
WsWorkerCommand::class,
|
2019-12-13 17:25:22 +08:00
|
|
|
]);
|
|
|
|
}
|
2019-12-07 17:31:38 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @time 2019年12月07日
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function registerValidates(): void
|
|
|
|
{
|
2020-01-14 18:32:30 +08:00
|
|
|
$validates = config('catch.validates');
|
2019-12-07 17:31:38 +08:00
|
|
|
|
2020-01-14 18:32:30 +08:00
|
|
|
Validate::maker(function($validate) use ($validates) {
|
2019-12-07 17:31:38 +08:00
|
|
|
foreach ($validates as $vali) {
|
2020-01-14 18:31:08 +08:00
|
|
|
$vali = app()->make($vali);
|
2019-12-07 17:31:38 +08:00
|
|
|
$validate->extend($vali->type(), [$vali, 'verify'], $vali->message());
|
|
|
|
}
|
|
|
|
});
|
2019-12-12 18:53:10 +08:00
|
|
|
}
|
2019-12-07 17:31:38 +08:00
|
|
|
|
2019-12-12 18:53:10 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @time 2019年12月12日
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function registerMiddleWares(): void
|
|
|
|
{
|
2020-02-18 14:44:16 +08:00
|
|
|
// todo
|
2019-12-02 23:04:43 +08:00
|
|
|
}
|
2019-12-12 22:34:08 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 注册监听者
|
|
|
|
*
|
|
|
|
* @time 2019年12月12日
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-04-17 06:48:14 +08:00
|
|
|
protected function registerEvents(): void
|
2019-12-12 22:34:08 +08:00
|
|
|
{
|
2020-02-20 13:44:54 +08:00
|
|
|
$this->app->event->listenEvents(config('catch.events'));
|
2019-12-12 22:34:08 +08:00
|
|
|
}
|
2020-01-13 16:23:08 +08:00
|
|
|
|
2020-02-20 13:44:54 +08:00
|
|
|
/**
|
|
|
|
* register query
|
|
|
|
*
|
|
|
|
* @time 2020年02月20日
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function registerQuery(): void
|
2020-01-13 16:23:08 +08:00
|
|
|
{
|
|
|
|
$connections = $this->app->config->get('database.connections');
|
|
|
|
|
|
|
|
$connections['mysql']['query'] = CatchQuery::class;
|
|
|
|
|
|
|
|
$this->app->config->set([
|
|
|
|
'connections' => $connections
|
|
|
|
], 'database');
|
|
|
|
}
|
2020-02-02 22:10:52 +08:00
|
|
|
|
2020-02-20 13:44:54 +08:00
|
|
|
/**
|
|
|
|
* register exception
|
|
|
|
*
|
|
|
|
* @time 2020年02月20日
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function registerExceptionHandle(): void
|
2020-02-02 22:10:52 +08:00
|
|
|
{
|
|
|
|
$this->app->bind(Handle::class, CatchExceptionHandle::class);
|
|
|
|
}
|
2019-12-26 09:03:09 +08:00
|
|
|
}
|