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
|
|
|
|
2020-06-24 09:46:21 +08:00
|
|
|
use catcher\command\install\ModuleServiceDiscoverCommand;
|
2020-06-06 22:37:36 +08:00
|
|
|
use catcher\command\publish\WechatCommand;
|
2020-04-29 15:06:13 +08:00
|
|
|
use catcher\command\Tools\BackupCommand;
|
2020-06-18 17:08:47 +08:00
|
|
|
use catcher\command\Tools\CacheTrieCommand;
|
2020-04-29 15:06:13 +08:00
|
|
|
use catcher\command\Tools\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-04-29 15:06:13 +08:00
|
|
|
use catcher\command\Tools\ExportDataCommand;
|
2020-05-08 20:56:21 +08:00
|
|
|
use catcher\command\Tools\MakeMenuCommand;
|
2020-06-08 08:54:50 +08:00
|
|
|
use catcher\command\worker\ExcelTaskCommand;
|
2020-01-24 08:40:04 +08:00
|
|
|
use catcher\command\worker\WsWorkerCommand;
|
2020-06-24 09:11:48 +08:00
|
|
|
use catcher\event\LoadModuleRoutes;
|
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-06-24 09:11:48 +08:00
|
|
|
{}
|
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();
|
2020-06-24 09:11:48 +08:00
|
|
|
$this->registerRoutePath();
|
|
|
|
$this->registerServices();
|
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,
|
2020-05-08 20:56:21 +08:00
|
|
|
ExportDataCommand::class,
|
|
|
|
MakeMenuCommand::class,
|
2020-06-08 08:54:50 +08:00
|
|
|
ExcelTaskCommand::class,
|
2020-06-18 17:08:47 +08:00
|
|
|
WechatCommand::class,
|
|
|
|
CacheTrieCommand::class,
|
2020-06-24 09:46:21 +08:00
|
|
|
ModuleServiceDiscoverCommand::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-06-24 09:11:48 +08:00
|
|
|
$this->app->event->listenEvents([
|
|
|
|
'RouteLoaded' => [LoadModuleRoutes::class]
|
|
|
|
]);
|
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);
|
|
|
|
}
|
2020-06-24 09:11:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 注册模块服务
|
|
|
|
*
|
|
|
|
* @time 2020年06月23日
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function registerServices()
|
|
|
|
{
|
|
|
|
$services = CatchAdmin::getEnabledService();
|
|
|
|
|
|
|
|
foreach ($services as $service) {
|
|
|
|
if (class_exists($service)) {
|
|
|
|
$this->app->register($service);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 注册路由地址
|
|
|
|
*
|
|
|
|
* @time 2020年06月23日
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function registerRoutePath()
|
|
|
|
{
|
|
|
|
$this->app->instance('routePath', new class {
|
|
|
|
protected $path = [];
|
|
|
|
public function loadRouterFrom($path)
|
|
|
|
{
|
|
|
|
$this->path[] = $path;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
public function get()
|
|
|
|
{
|
|
|
|
return $this->path;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-12-26 09:03:09 +08:00
|
|
|
}
|