fixed conflict
This commit is contained in:
134
extend/catcher/CatchAdminService.php
Normal file
134
extend/catcher/CatchAdminService.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
namespace catcher;
|
||||
|
||||
use catcher\command\BackupCommand;
|
||||
use catcher\command\CompressPackageCommand;
|
||||
use catcher\command\CreateModuleCommand;
|
||||
use catcher\command\InstallCommand;
|
||||
use catcher\command\MigrateCreateCommand;
|
||||
use catcher\command\MigrateRollbackCommand;
|
||||
use catcher\command\MigrateRunCommand;
|
||||
use catcher\command\ModelGeneratorCommand;
|
||||
use catcher\command\ModuleCacheCommand;
|
||||
use catcher\command\SeedRunCommand;
|
||||
use catcher\command\worker\WsWorkerCommand;
|
||||
use think\exception\Handle;
|
||||
use think\facade\Validate;
|
||||
use think\Service;
|
||||
|
||||
class CatchAdminService extends Service
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @time 2019年11月29日
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* register
|
||||
*
|
||||
* @author JaguarJack
|
||||
* @email njphper@gmail.com
|
||||
* @time 2020/1/30
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->registerCommands();
|
||||
$this->registerValidates();
|
||||
$this->registerMiddleWares();
|
||||
$this->registerListeners();
|
||||
$this->registerQuery();
|
||||
$this->registerExceptionHandle();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月13日
|
||||
* @return void
|
||||
*/
|
||||
protected function registerCommands(): void
|
||||
{
|
||||
$this->commands([
|
||||
InstallCommand::class,
|
||||
ModuleCacheCommand::class,
|
||||
MigrateRunCommand::class,
|
||||
ModelGeneratorCommand::class,
|
||||
SeedRunCommand::class,
|
||||
BackupCommand::class,
|
||||
CompressPackageCommand::class,
|
||||
CreateModuleCommand::class,
|
||||
MigrateRollbackCommand::class,
|
||||
MigrateCreateCommand::class,
|
||||
WsWorkerCommand::class,
|
||||
]);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月07日
|
||||
* @return void
|
||||
*/
|
||||
protected function registerValidates(): void
|
||||
{
|
||||
$validates = config('catch.validates');
|
||||
|
||||
Validate::maker(function($validate) use ($validates) {
|
||||
foreach ($validates as $vali) {
|
||||
$vali = app()->make($vali);
|
||||
$validate->extend($vali->type(), [$vali, 'verify'], $vali->message());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月12日
|
||||
* @return void
|
||||
*/
|
||||
protected function registerMiddleWares(): void
|
||||
{
|
||||
// todo
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册监听者
|
||||
*
|
||||
* @time 2019年12月12日
|
||||
* @return void
|
||||
*/
|
||||
protected function registerListeners(): void
|
||||
{
|
||||
$this->app->event->listenEvents(config('catch.events'));
|
||||
}
|
||||
|
||||
/**
|
||||
* register query
|
||||
*
|
||||
* @time 2020年02月20日
|
||||
* @return void
|
||||
*/
|
||||
protected function registerQuery(): void
|
||||
{
|
||||
$connections = $this->app->config->get('database.connections');
|
||||
|
||||
$connections['mysql']['query'] = CatchQuery::class;
|
||||
|
||||
$this->app->config->set([
|
||||
'connections' => $connections
|
||||
], 'database');
|
||||
}
|
||||
|
||||
/**
|
||||
* register exception
|
||||
*
|
||||
* @time 2020年02月20日
|
||||
* @return void
|
||||
*/
|
||||
protected function registerExceptionHandle(): void
|
||||
{
|
||||
$this->app->bind(Handle::class, CatchExceptionHandle::class);
|
||||
}
|
||||
}
|
@@ -1,61 +1,61 @@
|
||||
<?php
|
||||
namespace catcher;
|
||||
|
||||
use app\ExceptionHandle;
|
||||
use catcher\exceptions\CatchException;
|
||||
use catcher\exceptions\FailedException;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\exception\Handle;
|
||||
use think\exception\HttpException;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\exception\ValidateException;
|
||||
use think\Response;
|
||||
use Throwable;
|
||||
|
||||
class CatchExceptionHandle extends Handle
|
||||
{
|
||||
/**
|
||||
* 不需要记录信息(日志)的异常类列表
|
||||
* @var array
|
||||
*/
|
||||
protected $ignoreReport = [
|
||||
HttpException::class,
|
||||
HttpResponseException::class,
|
||||
ModelNotFoundException::class,
|
||||
DataNotFoundException::class,
|
||||
ValidateException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* 记录异常信息(包括日志或者其它方式记录)
|
||||
*
|
||||
* @access public
|
||||
* @param Throwable $exception
|
||||
* @return void
|
||||
*/
|
||||
public function report(Throwable $exception): void
|
||||
{
|
||||
// 使用内置的方式记录异常日志
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @access public
|
||||
* @param \think\Request $request
|
||||
* @param Throwable $e
|
||||
* @return Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function render($request, Throwable $e): Response
|
||||
{
|
||||
// 其他错误交给系统处理
|
||||
if (!$e instanceof CatchException) {
|
||||
$e = new FailedException($e->getMessage());
|
||||
}
|
||||
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
namespace catcher;
|
||||
|
||||
use app\ExceptionHandle;
|
||||
use catcher\exceptions\CatchException;
|
||||
use catcher\exceptions\FailedException;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\exception\Handle;
|
||||
use think\exception\HttpException;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\exception\ValidateException;
|
||||
use think\Response;
|
||||
use Throwable;
|
||||
|
||||
class CatchExceptionHandle extends Handle
|
||||
{
|
||||
/**
|
||||
* 不需要记录信息(日志)的异常类列表
|
||||
* @var array
|
||||
*/
|
||||
protected $ignoreReport = [
|
||||
HttpException::class,
|
||||
HttpResponseException::class,
|
||||
ModelNotFoundException::class,
|
||||
DataNotFoundException::class,
|
||||
ValidateException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* 记录异常信息(包括日志或者其它方式记录)
|
||||
*
|
||||
* @access public
|
||||
* @param Throwable $exception
|
||||
* @return void
|
||||
*/
|
||||
public function report(Throwable $exception): void
|
||||
{
|
||||
// 使用内置的方式记录异常日志
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @access public
|
||||
* @param \think\Request $request
|
||||
* @param Throwable $e
|
||||
* @return Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function render($request, Throwable $e): Response
|
||||
{
|
||||
// 其他错误交给系统处理
|
||||
if (!$e instanceof CatchException) {
|
||||
$e = new FailedException($e->getMessage());
|
||||
}
|
||||
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
}
|
||||
|
@@ -1,433 +0,0 @@
|
||||
<?php
|
||||
namespace catcher;
|
||||
|
||||
/**
|
||||
* Class CatchForm
|
||||
* @package catcher
|
||||
*
|
||||
*
|
||||
* @method CatchForm text($column, $label = '', $required = false)
|
||||
* @method CatchForm image($column, $label = '', $required = false)
|
||||
* @method CatchForm radio($column, $label = '', $required = false)
|
||||
* @method CatchForm select($column, $label = '', $required = false)
|
||||
* @method CatchForm textarea($column, $label = '', $required = false)
|
||||
* @method CatchForm password($column, $label = '', $required = false)
|
||||
* @method CatchForm hidden($column, $label = '', $required = false)
|
||||
* @method CatchForm dom($column, $label = '', $required = false)
|
||||
*
|
||||
*/
|
||||
class CatchForm
|
||||
{
|
||||
protected $name;
|
||||
|
||||
private $fields = [];
|
||||
|
||||
protected $action;
|
||||
|
||||
protected $method;
|
||||
|
||||
protected $enctype;
|
||||
|
||||
protected $formId;
|
||||
|
||||
protected $btn;
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param $acton
|
||||
* @return CatchForm
|
||||
*/
|
||||
public function action($acton): CatchForm
|
||||
{
|
||||
$this->action = $acton;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param $method
|
||||
* @return CatchForm
|
||||
*/
|
||||
public function method($method): CatchForm
|
||||
{
|
||||
$this->method = $method;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param $formId
|
||||
* @return CatchForm
|
||||
*/
|
||||
public function formId($formId): CatchForm
|
||||
{
|
||||
$this->formId = $formId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param string $enctype
|
||||
* @return CatchForm
|
||||
*/
|
||||
public function enctype($enctype ="multipart/form-data"): CatchForm
|
||||
{
|
||||
$this->enctype = $enctype;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param $id
|
||||
* @return CatchForm
|
||||
*/
|
||||
public function id($id): CatchForm
|
||||
{
|
||||
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||
'id' => sprintf('id="%s"', $id),
|
||||
]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param string $class
|
||||
* @param string $labelClass
|
||||
* @param string $inlineClass
|
||||
* @return CatchForm
|
||||
*/
|
||||
public function class($class='', $labelClass = '', $inlineClass = ''): CatchForm
|
||||
{
|
||||
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||
'class' => $class,
|
||||
'labelClass' => $labelClass,
|
||||
'inlineClass' => $inlineClass,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param array $options
|
||||
* @return CatchForm
|
||||
*/
|
||||
public function options(array $options): CatchForm
|
||||
{
|
||||
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||
'options' => $options,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param $value
|
||||
* @return CatchForm
|
||||
*/
|
||||
public function default($value): CatchForm
|
||||
{
|
||||
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||
'default' => $value,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @return CatchForm
|
||||
*/
|
||||
public function disabled(): CatchForm
|
||||
{
|
||||
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||
'disabled' => '',
|
||||
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param $content
|
||||
* @return CatchForm
|
||||
*/
|
||||
public function placeholder($content): CatchForm
|
||||
{
|
||||
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||
'placeholder' => 'placeholder='.$content,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @return CatchForm
|
||||
*/
|
||||
public function readonly(): CatchForm
|
||||
{
|
||||
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||
'readonly' => 'readonly',
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @return string
|
||||
*/
|
||||
public function render(): string
|
||||
{
|
||||
$form = sprintf('<form id="%s" lay-filter="%s" class="layui-form model-form">', $this->formId, $this->formId);
|
||||
|
||||
foreach ($this->fields as $field) {
|
||||
$form .= in_array($field['type'], ['hidden']) ?
|
||||
$this->{$field['type'].'Field'}($field)
|
||||
: sprintf($this->baseField(),
|
||||
$field['labelClass'] ?? '',
|
||||
$field['label'],
|
||||
$field['inlineClass'] ?? '',
|
||||
$this->{$field['type'].'Field'}($field));
|
||||
}
|
||||
|
||||
return $form . $this->btn. '</form>';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param $append
|
||||
* @return CatchForm
|
||||
*/
|
||||
public function append($append): CatchForm
|
||||
{
|
||||
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||
'append' => $append,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param $method
|
||||
* @param $arguments
|
||||
* @return $this
|
||||
*/
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
// TODO: Implement __call() method.
|
||||
$this->name = $arguments[0] ?? '';
|
||||
$label = $arguments[1] ?? '';
|
||||
$required = $arguments[2] ?? false;
|
||||
|
||||
$this->fields[$this->name] = [
|
||||
'name' => $this->name,
|
||||
'type' => $method,
|
||||
'label' => $required ? '<i style="color:red">*</i> '.$label : $label,
|
||||
'inline' => false,
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @return CatchForm
|
||||
*/
|
||||
protected function inline(): CatchForm
|
||||
{
|
||||
$this->fields[] = array_merge($this->fields, [
|
||||
'inline' => true,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @return string
|
||||
*/
|
||||
private function baseField(): string
|
||||
{
|
||||
return
|
||||
'<div class="layui-form-item">
|
||||
<label class="layui-form-label%s">%s: </label>
|
||||
<div class="layui-input-block%s">
|
||||
%s
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* form btn
|
||||
*
|
||||
* @time 2019年12月06日
|
||||
* @param $filter
|
||||
* @param string $position
|
||||
* @return CatchForm
|
||||
*/
|
||||
public function formBtn($filter, $position = 'text-right'): CatchForm
|
||||
{
|
||||
$this->btn = sprintf('<div class="layui-form-item %s">
|
||||
<button class="layui-btn layui-btn-primary" type="button" ew-event="closePageDialog">取消</button>
|
||||
<button class="layui-btn" lay-filter="%s" lay-submit>保存</button>
|
||||
</div>', $position, $filter);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param $rule
|
||||
* @param array $equalTo
|
||||
* @return CatchForm
|
||||
*/
|
||||
public function verify($rule, $equalTo = []): CatchForm
|
||||
{
|
||||
if (empty($equalTo)) {
|
||||
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||
'verify' => sprintf('lay-verType="tips" lay-verify="%s"', $rule),
|
||||
]);
|
||||
} else {
|
||||
[$id, $msg] = $equalTo;
|
||||
|
||||
$this->fields[$this->name] = array_merge($this->fields[$this->name], [
|
||||
'verify' => sprintf(' lay-verType="tips" lay-verify="%s" lay-equalTo="#%s"
|
||||
lay-equalToText="%s" ', $rule, $id, $msg),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param $field
|
||||
* @return string
|
||||
*/
|
||||
private function textField($field)
|
||||
{
|
||||
return
|
||||
sprintf('<input name="%s" class="layui-input %s" %s value="%s" type="text" %s %s %s%s>',
|
||||
$field['name'],
|
||||
$field['id'] ?? '',
|
||||
$field['class'] ?? '',
|
||||
$field['default'] ?? '',
|
||||
$field['readonly'] ?? '',
|
||||
$field['placeholder'] ?? '',
|
||||
$field['disabled'] ?? '',
|
||||
$field['verify'] ?? ''
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param $field
|
||||
* @return string
|
||||
*/
|
||||
private function selectField($field)
|
||||
{
|
||||
$select = sprintf('<select name="%s" %s>', $field['name'], $field['verify'] ?? '');
|
||||
|
||||
$default = $field['default'] ?? '';
|
||||
|
||||
foreach ($field['options'] as $key => $option) {
|
||||
$select .= sprintf('<option value="%s"%s>%s</option>', $option['value'], $default == $key ? ' selected' : '',$option['title']);
|
||||
}
|
||||
|
||||
return $select . '</select>';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param $field
|
||||
* @return string
|
||||
*/
|
||||
private function passwordField($field)
|
||||
{
|
||||
return sprintf('<input name="%s" class="layui-input" %s type="password" %s %s>',
|
||||
$field['name'],
|
||||
$field['id'] ?? '',
|
||||
$field['verify'] ?? '',
|
||||
$field['placeholder'] ?? ''
|
||||
);
|
||||
}
|
||||
|
||||
private function radioField($field)
|
||||
{
|
||||
$radio = '';
|
||||
foreach ($field['options'] as $option) {
|
||||
$radio .= sprintf('<input name="%s" type="radio" value="%s" title="%s" %s/>',
|
||||
$field['name'], $option['value'], $option['title'], $option['value'] == $field['default'] ? 'checked' : ''
|
||||
);
|
||||
}
|
||||
|
||||
return $radio;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月09日
|
||||
* @param $field
|
||||
* @return string
|
||||
*/
|
||||
private function textareaField($field): string
|
||||
{
|
||||
return sprintf('<textarea name="%s" %s class="layui-textarea">%s</textarea>',
|
||||
$field['name'],
|
||||
$field['placeholder'] ?? '',
|
||||
$field['default'] ?? ''
|
||||
);
|
||||
}
|
||||
|
||||
private function domField($field)
|
||||
{
|
||||
return $field['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月10日
|
||||
* @param $field
|
||||
* @return string
|
||||
*/
|
||||
private function hiddenField($field): string
|
||||
{
|
||||
return sprintf('<input name="%s" value="%s" type="hidden">',
|
||||
$field['name'], $field['default']
|
||||
);
|
||||
}
|
||||
|
||||
private function imageField()
|
||||
{}
|
||||
|
||||
}
|
@@ -129,11 +129,17 @@ class InstallCommand extends Command
|
||||
$prefix = $this->output->ask($this->input, '👉 please input table prefix, default (null):') ? : '';
|
||||
$username = $this->output->ask($this->input, '👉 please input database username default (root): ') ? : 'root';
|
||||
$password = '';
|
||||
$tryTimes = 0;
|
||||
while (!$password) {
|
||||
$password = $this->output->ask($this->input, '👉 please input database password: ');
|
||||
if ($password) {
|
||||
break;
|
||||
}
|
||||
// 尝试三次以上未填写,视为密码空
|
||||
$tryTimes++;
|
||||
if (!$password && $tryTimes > 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->databaseLink = [$host, $database, $username, $password, $port, $charset, $prefix];
|
||||
|
@@ -3,6 +3,7 @@ declare (strict_types = 1);
|
||||
|
||||
namespace catcher\event;
|
||||
|
||||
use catchAdmin\permissions\PermissionsMiddleware;
|
||||
use catchAdmin\user\AuthTokenMiddleware;
|
||||
use catcher\CatchAdmin;
|
||||
use think\Route;
|
||||
@@ -23,18 +24,20 @@ class LoadModuleRoutes
|
||||
|
||||
$routes = CatchAdmin::getRoutes();
|
||||
|
||||
$routeMiddleware = config('catch.route_middleware');
|
||||
|
||||
if ($domain) {
|
||||
$router->domain($domain, function () use ($router, $routes) {
|
||||
foreach ($routes as $route) {
|
||||
include $route;
|
||||
}
|
||||
})->middleware([AuthTokenMiddleware::class]);
|
||||
})->middleware($routeMiddleware);
|
||||
} else {
|
||||
$router->group(function () use ($router, $routes) {
|
||||
foreach ($routes as $route) {
|
||||
include $route;
|
||||
}
|
||||
})->middleware([AuthTokenMiddleware::class]);
|
||||
})->middleware($routeMiddleware);
|
||||
}
|
||||
|
||||
// 单独加载登录
|
||||
|
Reference in New Issue
Block a user