catchAdmin/catch/CatchAdminService.php

136 lines
3.3 KiB
PHP
Raw Normal View History

2019-12-02 23:04:43 +08:00
<?php
namespace catchAdmin;
2019-12-12 22:34:08 +08:00
use catchAdmin\login\LoginLogListener;
use catchAdmin\permissions\OperateLogListener;
2019-12-12 18:53:10 +08:00
use catchAdmin\permissions\PermissionsMiddleware;
2019-12-12 22:34:08 +08:00
use catchAdmin\system\event\LoginLogEvent;
use catchAdmin\system\event\OperateLogEvent;
2020-01-13 16:23:08 +08:00
use catcher\CatchQuery;
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;
2019-12-02 23:04:43 +08:00
use catcher\command\InstallCommand;
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;
2019-12-13 17:25:22 +08:00
use catcher\event\LoadModuleRoutes;
2019-12-07 17:31:38 +08:00
use catcher\validates\Sometimes;
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();
2019-12-12 22:34:08 +08:00
$this->registerListeners();
2020-01-13 16:23:08 +08:00
$this->registerQuery();
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([
InstallCommand::class,
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
{
$this->app->middleware->import([
2020-01-25 20:03:18 +08:00
'catch_check_permission' => PermissionsMiddleware::class,
2019-12-12 18:53:10 +08:00
], 'route');
2019-12-02 23:04:43 +08:00
}
2019-12-12 22:34:08 +08:00
/**
* 注册监听者
*
* @time 2019年12月12日
* @return void
*/
protected function registerListeners(): void
{
$this->app->event->listenEvents([
'loginLog' => [
LoginLogListener::class,
],
'operateLog' => [
OperateLogListener::class,
],
2019-12-13 17:25:22 +08:00
'RouteLoaded' => [
LoadModuleRoutes::class
2020-01-09 08:22:25 +08:00
],
2019-12-12 22:34:08 +08:00
]);
}
2020-01-13 16:23:08 +08:00
protected function registerQuery()
{
$connections = $this->app->config->get('database.connections');
$connections['mysql']['query'] = CatchQuery::class;
$this->app->config->set([
'connections' => $connections
], 'database');
}
2019-12-26 09:03:09 +08:00
}