Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
dcbe82f398 | ||
![]() |
afe70d39b9 | ||
![]() |
9118e07d7b | ||
![]() |
c0f05fcf8f | ||
![]() |
35445f37e1 | ||
![]() |
94c430f491 | ||
![]() |
97efb82971 | ||
![]() |
5f49a22a5e | ||
![]() |
85f4fc0df8 | ||
![]() |
04a7818608 | ||
![]() |
21c1df4f69 | ||
![]() |
0dfe4fb5c6 | ||
![]() |
9ca1fd42ae | ||
![]() |
5713d12ce1 | ||
![]() |
e01790aa23 | ||
![]() |
ecf0970ca4 | ||
![]() |
78e782dd01 | ||
![]() |
e4a5ae0c37 | ||
![]() |
c8e9e6361c | ||
![]() |
7c4fa5c516 | ||
![]() |
97b7f73ff2 | ||
![]() |
0b5c883012 | ||
![]() |
a9671b6227 | ||
![]() |
9ab22b1a1c | ||
![]() |
a931b7597c |
@@ -141,7 +141,7 @@ composer create-project jaguarjack/catchadmin:dev-master
|
||||
|
||||
### Donate
|
||||
如果你觉得项目对你有帮助,可以请作者喝杯咖啡☕️!鼓励下
|
||||
<img src="https://cdn.learnku.com/uploads/images/202008/11/18206/e6qAAM8Bod.jpg!large">
|
||||
<!--<img src="https://cdn.learnku.com/uploads/images/202008/11/18206/e6qAAM8Bod.jpg!large">-->
|
||||
|
||||
### Talking
|
||||
- [论坛讨论](http://bbs.catchadmin.com)
|
||||
|
@@ -29,7 +29,7 @@ class Index extends CatchController
|
||||
|
||||
$user = $auth->user();
|
||||
|
||||
$this->afterLoginSuccess($user);
|
||||
$this->afterLoginSuccess($user, $token);
|
||||
// 登录事件
|
||||
$this->loginEvent($user->username);
|
||||
|
||||
@@ -70,12 +70,16 @@ class Index extends CatchController
|
||||
*
|
||||
* @time 2020年09月09日
|
||||
* @param $user
|
||||
* @param $token
|
||||
* @return void
|
||||
*/
|
||||
protected function afterLoginSuccess($user)
|
||||
protected function afterLoginSuccess($user, $token)
|
||||
{
|
||||
$user->last_login_ip = request()->ip();
|
||||
$user->last_login_time = time();
|
||||
if ($user->hasField('remember_token')) {
|
||||
$user->remember_token = $token;
|
||||
}
|
||||
$user->save();
|
||||
}
|
||||
|
||||
|
@@ -9,12 +9,13 @@ use catcher\CatchResponse;
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\Tree;
|
||||
use think\response\Json;
|
||||
use catchAdmin\permissions\model\Roles as RoleModel;
|
||||
|
||||
class Role extends CatchController
|
||||
{
|
||||
protected $role;
|
||||
|
||||
public function __construct(\catchAdmin\permissions\model\Roles $role)
|
||||
public function __construct(RoleModel $role)
|
||||
{
|
||||
$this->role = $role;
|
||||
}
|
||||
@@ -22,7 +23,6 @@ class Role extends CatchController
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月09日
|
||||
* @param Request $request
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
@@ -50,9 +50,7 @@ class Role extends CatchController
|
||||
if (!empty($permissions)) {
|
||||
$this->role->attachPermissions(array_unique($permissions));
|
||||
}
|
||||
if (!empty($params['permissions'])) {
|
||||
$this->role->attachDepartments($params['permissions']);
|
||||
}
|
||||
|
||||
// 添加角色
|
||||
return CatchResponse::success();
|
||||
}
|
||||
@@ -61,7 +59,6 @@ class Role extends CatchController
|
||||
{
|
||||
$role = $this->role->findBy($id);
|
||||
$role->permissions = $role->getPermissions();
|
||||
$role->departments = $role->getDepartments();
|
||||
return CatchResponse::success($role);
|
||||
}
|
||||
|
||||
@@ -104,28 +101,6 @@ class Role extends CatchController
|
||||
$role->attachPermissions(array_unique($attachIds));
|
||||
}
|
||||
|
||||
// 更新department
|
||||
$hasDepartmentIds = $role->getDepartments()->column('id');
|
||||
$departmentIds = $request->param('departments',[]);
|
||||
|
||||
// 已存在部门 IDS
|
||||
$existedDepartmentIds = [];
|
||||
foreach ($hasDepartmentIds as $hasDepartmentId) {
|
||||
if (in_array($hasDepartmentId, $departmentIds)) {
|
||||
$existedDepartmentIds[] = $hasDepartmentId;
|
||||
}
|
||||
}
|
||||
|
||||
$attachDepartmentIds = array_diff($departmentIds, $existedDepartmentIds);
|
||||
$detachDepartmentIds = array_diff($hasDepartmentIds, $existedDepartmentIds);
|
||||
|
||||
if (!empty($detachDepartmentIds)) {
|
||||
$role->detachDepartments($detachDepartmentIds);
|
||||
}
|
||||
if (!empty($attachDepartmentIds)) {
|
||||
$role->attachDepartments(array_unique($attachDepartmentIds));
|
||||
}
|
||||
|
||||
return CatchResponse::success();
|
||||
}
|
||||
|
||||
@@ -147,8 +122,6 @@ class Role extends CatchController
|
||||
$role = $this->role->findBy($id);
|
||||
// 删除权限
|
||||
$role->detachPermissions();
|
||||
// 删除部门关联
|
||||
$role->detachDepartments();
|
||||
// 删除用户关联
|
||||
$role->users()->detach();
|
||||
// 删除
|
||||
|
@@ -8,6 +8,7 @@ use catchAdmin\permissions\model\Roles;
|
||||
use catchAdmin\permissions\model\Users;
|
||||
use catchAdmin\permissions\request\CreateRequest;
|
||||
use catchAdmin\permissions\request\UpdateRequest;
|
||||
use catchAdmin\permissions\request\ProfileRequest;
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchAuth;
|
||||
use catcher\CatchCacheKeys;
|
||||
@@ -67,15 +68,6 @@ class User extends CatchController
|
||||
return CatchResponse::success($user);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月06日
|
||||
* @throws \Exception
|
||||
* @return string
|
||||
*/
|
||||
public function create()
|
||||
{}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param CreateRequest $request
|
||||
@@ -109,12 +101,6 @@ class User extends CatchController
|
||||
return CatchResponse::success($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function edit($id){}
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月04日
|
||||
@@ -248,10 +234,10 @@ class User extends CatchController
|
||||
* 更新个人信息
|
||||
*
|
||||
* @time 2020年09月20日
|
||||
* @param Request $request
|
||||
* @param ProfileRequest $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function profile(Request $request)
|
||||
public function profile(ProfileRequest $request)
|
||||
{
|
||||
return CatchResponse::success($this->user->updateBy($request->user()->id, $request->param()));
|
||||
}
|
||||
|
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
|
||||
class AddUserRememberToken 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()
|
||||
{
|
||||
if ($this->hasTable('users')) {
|
||||
$table = $this->table('users');
|
||||
|
||||
$table->addColumn('remember_token', 'string', [
|
||||
'limit' => 512,
|
||||
'default' => '',
|
||||
'comment' => '用户token',
|
||||
'after' => 'avatar'])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
}
|
@@ -39,4 +39,23 @@ class Department extends CatchModel
|
||||
->catchOrder()
|
||||
->select()->toTree();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子部门IDS
|
||||
*
|
||||
* @time 2020年11月04日
|
||||
* @param $id
|
||||
* @throws DbException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getChildrenDepartmentIds($id)
|
||||
{
|
||||
$departmentIds = Department::field(['id', 'parent_id'])->select()->getAllChildrenIds([$id]);
|
||||
|
||||
$departmentIds[] = $id;
|
||||
|
||||
return $departmentIds;
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ class Users extends CatchModel
|
||||
'password', // 用户密码
|
||||
'email', // 邮箱 登录
|
||||
'avatar', // 头像
|
||||
'remember_token',
|
||||
'creator_id', // 创建者ID
|
||||
'department_id', // 部门ID
|
||||
'status', // 用户状态 1 正常 2 禁用
|
||||
@@ -28,7 +29,6 @@ class Users extends CatchModel
|
||||
'created_at', // 创建时间
|
||||
'updated_at', // 更新时间
|
||||
'deleted_at', // 删除状态,0未删除 >0 已删除
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
|
@@ -20,10 +20,20 @@ trait UserSearch
|
||||
return $query->where($this->aliasField('status'), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询部门下的用户
|
||||
*
|
||||
* @time 2020年11月04日
|
||||
* @param $query
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return mixed
|
||||
*/
|
||||
public function searchDepartmentIdAttr($query, $value, $data)
|
||||
{
|
||||
$departmentIds = Department::where('parent_id', $value)->column('id');
|
||||
$departmentIds[] = $value;
|
||||
return $query->whereIn($this->aliasField('department_id'), $departmentIds);
|
||||
return $query->whereIn($this->aliasField('department_id'), Department::getChildrenDepartmentIds($value));
|
||||
}
|
||||
}
|
||||
|
17
catch/permissions/request/ProfileRequest.php
Normal file
17
catch/permissions/request/ProfileRequest.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace catchAdmin\permissions\request;
|
||||
|
||||
use catchAdmin\permissions\model\Users;
|
||||
use catcher\base\CatchRequest;
|
||||
|
||||
class ProfileRequest extends CatchRequest
|
||||
{
|
||||
protected function rules(): array
|
||||
{
|
||||
// TODO: Implement rules() method.
|
||||
return [
|
||||
'username|用户名' => 'require|max:20',
|
||||
'email|邮箱' => 'require|email|unique:'.Users::class . ',email,' . $this->user()->id,
|
||||
];
|
||||
}
|
||||
}
|
@@ -15,9 +15,4 @@ class UpdateRequest extends CatchRequest
|
||||
'email|邮箱' => 'require|email|unique:'.Users::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function message()
|
||||
{
|
||||
// TODO: Implement message() method.
|
||||
}
|
||||
}
|
||||
|
@@ -11,11 +11,10 @@ $router->group(function () use ($router){
|
||||
|
||||
// 部门
|
||||
$router->resource('departments', '\catchAdmin\permissions\controller\Department');
|
||||
// 所有职位
|
||||
$router->get('jobs/all', '\catchAdmin\permissions\controller\Job@getAll');
|
||||
// 岗位
|
||||
$router->resource('jobs', '\catchAdmin\permissions\controller\Job');
|
||||
|
||||
$router->get('jobs/all', '\catchAdmin\permissions\controller\Job@getAll');
|
||||
|
||||
// 用户
|
||||
$router->resource('users', '\catchAdmin\permissions\controller\User');
|
||||
// 切换状态
|
||||
|
@@ -3,6 +3,7 @@ namespace catchAdmin\system\controller;
|
||||
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\generate\CreateModule;
|
||||
use catcher\generate\Generator;
|
||||
use think\Request;
|
||||
|
||||
@@ -25,4 +26,10 @@ class Generate extends CatchController
|
||||
{
|
||||
return CatchResponse::success($generator->preview($request->param()));
|
||||
}
|
||||
|
||||
|
||||
public function createModule(Request $request, CreateModule $module)
|
||||
{
|
||||
return CatchResponse::success($module->generate($request->post()));
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ use catcher\base\CatchController;
|
||||
use catcher\base\CatchRequest;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\CatchUpload;
|
||||
use catcher\exceptions\FailedException;
|
||||
|
||||
class Upload extends CatchController
|
||||
{
|
||||
@@ -37,6 +38,10 @@ class Upload extends CatchController
|
||||
{
|
||||
$images = $request->file();
|
||||
|
||||
if (!$images) {
|
||||
throw new FailedException('请选择图片上传');
|
||||
}
|
||||
|
||||
return CatchResponse::success($upload->checkImages($images)->multiUpload($images['image']));
|
||||
}
|
||||
|
||||
|
@@ -28,6 +28,7 @@ $router->group(function () use ($router) {
|
||||
// 代码生成
|
||||
$router->post('generate', '\catchAdmin\system\controller\Generate@save');
|
||||
$router->post('generate/preview', '\catchAdmin\system\controller\Generate@preview'); // 预览
|
||||
$router->post('generate/create/module', '\catchAdmin\system\controller\Generate@createModule'); // 创建模块
|
||||
|
||||
// 敏感词
|
||||
$router->resource('sensitive/word', '\catchAdmin\system\controller\SensitiveWord');
|
||||
|
@@ -18,7 +18,7 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.0",
|
||||
"topthink/framework": "6.0.4",
|
||||
"topthink/framework": "6.0.5",
|
||||
"topthink/think-orm": "2.0.33",
|
||||
"topthink/think-migration": "^3.0",
|
||||
"thans/tp-jwt-auth": "1.1",
|
||||
@@ -29,12 +29,14 @@
|
||||
"symfony/finder": "^4.4",
|
||||
"ext-json": "*",
|
||||
"overtrue/easy-sms": "^1.1",
|
||||
"jaguarjack/migration-generator": "dev-master"
|
||||
"jaguarjack/migration-generator": "dev-master",
|
||||
"lcobucci/jwt": "3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"topthink/think-trace":"^1.0",
|
||||
"topthink/think-trace": "^1.0",
|
||||
"symfony/var-dumper": "^5.1",
|
||||
"swoole/ide-helper": "^4.5"
|
||||
"swoole/ide-helper": "^4.5",
|
||||
"nikic/php-parser": "^4.10"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use think\helper\Arr;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use catcher\event\LoadModuleRoutes;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use catchAdmin\permissions\model\Users;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @filename CacheKeys.php
|
||||
* @createdAt 2020/1/17
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
@@ -12,6 +14,7 @@ namespace catcher;
|
||||
|
||||
use catcher\library\Composer;
|
||||
use catcher\facade\FileSystem;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
use think\App;
|
||||
use think\console\Command;
|
||||
|
||||
@@ -43,9 +46,9 @@ class CatchConsole
|
||||
/* \Symfony\Component\Finder\SplFileInfo $command */
|
||||
foreach ($commandFiles as $command) {
|
||||
if ($command->getExtension() === 'php') {
|
||||
$lastPath = str_replace($this->parseNamespace(), '',pathinfo($command, PATHINFO_DIRNAME));
|
||||
$lastPath = str_replace($this->parseNamespace(), '', pathinfo($command->getPathname(), PATHINFO_DIRNAME));
|
||||
$namespace = $this->namespace . str_replace(DIRECTORY_SEPARATOR, '\\', $lastPath) . '\\';
|
||||
$commandClass = $namespace . pathinfo($command, PATHINFO_FILENAME);
|
||||
$commandClass = $namespace . pathinfo($command->getPathname(), PATHINFO_FILENAME);
|
||||
$commands[] = $commandClass;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use app\ExceptionHandle;
|
||||
|
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use catcher\library\excel\CatchExcel;
|
||||
use catcher\library\excel\Excel;
|
||||
use catcher\library\excel\ExcelContract;
|
||||
use think\facade\Cache;
|
||||
@@ -83,4 +84,28 @@ class CatchModelCollection extends Collection
|
||||
{
|
||||
return Cache::store($store)->set($key, $this->items, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前级别下的所有子级
|
||||
*
|
||||
* @time 2020年11月04日
|
||||
* @param array $ids
|
||||
* @param string $parentFields
|
||||
* @param string $column
|
||||
* @return array
|
||||
*/
|
||||
public function getAllChildrenIds(array $ids, $parentFields = 'parent_id', $column = 'id')
|
||||
{
|
||||
array_walk($ids, function (&$item){
|
||||
$item = intval($item);
|
||||
});
|
||||
|
||||
$childDepartmentIds = $this->whereIn($parentFields, $ids)->column($column);
|
||||
|
||||
if (!empty($childDepartmentIds)) {
|
||||
$childDepartmentIds = array_merge($childDepartmentIds, $this->getAllChildrenIds($childDepartmentIds));
|
||||
}
|
||||
|
||||
return $childDepartmentIds;
|
||||
}
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use catcher\base\CatchModel;
|
||||
@@ -11,7 +13,7 @@ class CatchQuery extends Query
|
||||
/**
|
||||
*
|
||||
* @time 2020年01月13日
|
||||
* @param string $model
|
||||
* @param mixed $model
|
||||
* @param string $joinField
|
||||
* @param string $currentJoinField
|
||||
* @param array $field
|
||||
@@ -19,29 +21,38 @@ class CatchQuery extends Query
|
||||
* @param array $bind
|
||||
* @return CatchQuery
|
||||
*/
|
||||
public function catchJoin(string $model, string $joinField, string $currentJoinField, array $field = [], string $type = 'INNER', array $bind = []): CatchQuery
|
||||
public function catchJoin($model, string $joinField, string $currentJoinField, array $field = [], string $type = 'INNER', array $bind = []): CatchQuery
|
||||
{
|
||||
$tableAlias = null;
|
||||
|
||||
if (is_string($model)) {
|
||||
$table = app($model)->getTable();
|
||||
} else {
|
||||
list($model, $tableAlias) = $model;
|
||||
$table = app($model)->getTable();
|
||||
}
|
||||
|
||||
// 合并字段
|
||||
$this->options['field'] = array_merge($this->options['field'] ?? [], array_map(function ($value) use ($table) {
|
||||
return $table . '.' . $value;
|
||||
$this->options['field'] = array_merge($this->options['field'] ?? [], array_map(function ($value) use ($table, $tableAlias) {
|
||||
return ($tableAlias ? : $table) . '.' . $value;
|
||||
}, $field));
|
||||
|
||||
return $this->join($table, sprintf('%s.%s=%s.%s', $table, $joinField, $this->getAlias(), $currentJoinField), $type, $bind);
|
||||
return $this->join($tableAlias ? sprintf('%s %s', $table, $tableAlias) : $table
|
||||
|
||||
, sprintf('%s.%s=%s.%s', $tableAlias ? $tableAlias : $table, $joinField, $this->getAlias(), $currentJoinField), $type, $bind);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2020年01月13日
|
||||
* @param string $model
|
||||
* @param mixed $model
|
||||
* @param string $joinField
|
||||
* @param string $currentJoinField
|
||||
* @param array $field
|
||||
* @param array $bind
|
||||
* @return CatchQuery
|
||||
*/
|
||||
public function catchLeftJoin(string $model, string $joinField, string $currentJoinField, array $field = [], array $bind = []): CatchQuery
|
||||
public function catchLeftJoin($model, string $joinField, string $currentJoinField, array $field = [], array $bind = []): CatchQuery
|
||||
{
|
||||
return $this->catchJoin($model, $joinField, $currentJoinField, $field,'LEFT', $bind);
|
||||
}
|
||||
@@ -49,14 +60,14 @@ class CatchQuery extends Query
|
||||
/**
|
||||
*
|
||||
* @time 2020年01月13日
|
||||
* @param string $model
|
||||
* @param mixed $model
|
||||
* @param string $joinField
|
||||
* @param string $currentJoinField
|
||||
* @param array $field
|
||||
* @param array $bind
|
||||
* @return CatchQuery
|
||||
*/
|
||||
public function catchRightJoin(string $model, string $joinField, string $currentJoinField, array $field = [], array $bind = []): CatchQuery
|
||||
public function catchRightJoin($model, string $joinField, string $currentJoinField, array $field = [], array $bind = []): CatchQuery
|
||||
{
|
||||
return $this->catchJoin($model, $joinField, $currentJoinField, $field,'RIGHT', $bind);
|
||||
}
|
||||
@@ -118,7 +129,8 @@ class CatchQuery extends Query
|
||||
|
||||
foreach ($params as $field => $value) {
|
||||
$method = 'search' . Str::studly($field) . 'Attr';
|
||||
if ($value && method_exists($this->model, $method)) {
|
||||
// value in [null, '']
|
||||
if ($value !== null && $value !== '' && method_exists($this->model, $method)) {
|
||||
$this->model->$method($this, $value, $params);
|
||||
}
|
||||
}
|
||||
@@ -230,4 +242,32 @@ class CatchQuery extends Query
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段增加
|
||||
*
|
||||
* @time 2020年11月04日
|
||||
* @param $field
|
||||
* @param int $amount
|
||||
* @throws \think\db\exception\DbException
|
||||
* @return int
|
||||
*/
|
||||
public function increment($field, $amount = 1)
|
||||
{
|
||||
return $this->inc($field, $amount)->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段减少
|
||||
*
|
||||
* @time 2020年11月04日
|
||||
* @param $field
|
||||
* @param int $amount
|
||||
* @throws \think\db\exception\DbException
|
||||
* @return int
|
||||
*/
|
||||
public function decrement($field, $amount = 1)
|
||||
{
|
||||
return $this->dec($field, $amount)->update();
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use think\Paginator;
|
||||
use think\Response;
|
||||
use think\response\Json;
|
||||
|
||||
class CatchResponse
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use catchAdmin\system\model\Attachments;
|
||||
@@ -261,20 +263,11 @@ class CatchUpload
|
||||
if ($upload) {
|
||||
$disk = app()->config->get('filesystem.disks');
|
||||
|
||||
$uploadConfigs = $configModel->getConfig($upload->id);
|
||||
$uploadConfigs = $configModel->getConfig($upload->component);
|
||||
|
||||
// 重组
|
||||
$_config = [];
|
||||
if (!empty($uploadConfigs)) {
|
||||
foreach ($uploadConfigs as $key => $value) {
|
||||
list($object, $key) = explode('.', $key);
|
||||
$_config[$object][$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_config)) {
|
||||
// 读取上传可配置数据
|
||||
foreach ($_config as $key => &$config) {
|
||||
foreach ($uploadConfigs as $key => &$config) {
|
||||
// $disk[$key]['type'] = $key;
|
||||
// 腾讯云配置处理
|
||||
if (strtolower($key) == 'qcloud') {
|
||||
@@ -294,18 +287,19 @@ class CatchUpload
|
||||
}
|
||||
|
||||
// 合并数组
|
||||
array_walk($disk, function (&$item, $key) use ($_config) {
|
||||
array_walk($disk, function (&$item, $key) use ($uploadConfigs) {
|
||||
if (!in_array($key, ['public', 'local'])) {
|
||||
if ($_config[$key] ?? false) {
|
||||
foreach ($_config[$key] as $k => $value) {
|
||||
if ($uploadConfigs[$key] ?? false) {
|
||||
foreach ($uploadConfigs[$key] as $k => $value) {
|
||||
$item[$k] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 重新分配配置
|
||||
app()->config->set([
|
||||
'disk' => $disk,
|
||||
'disks' => $disk,
|
||||
], 'filesystem');
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
class Code
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
class Tree
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use catchAdmin\system\model\Config;
|
||||
@@ -149,6 +151,18 @@ class Utils
|
||||
return \config('database.connections.mysql.prefix');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除前缀
|
||||
*
|
||||
* @time 2020年12月01日
|
||||
* @param string $table
|
||||
* @return string|string[]
|
||||
*/
|
||||
public static function tableWithoutPrefix(string $table)
|
||||
{
|
||||
return str_replace(self::tablePrefix(), '', $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是超级管理员
|
||||
*
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\base;
|
||||
|
||||
abstract class CatchController
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\base;
|
||||
|
||||
use catcher\CatchQuery;
|
||||
@@ -33,4 +35,16 @@ abstract class CatchModel extends \think\Model
|
||||
public const ENABLE = 1;
|
||||
// 禁用
|
||||
public const DISABLE = 2;
|
||||
|
||||
/**
|
||||
* 是否有 field
|
||||
*
|
||||
* @time 2020年11月23日
|
||||
* @param string $field
|
||||
* @return bool
|
||||
*/
|
||||
public function hasField(string $field)
|
||||
{
|
||||
return property_exists($this, 'field') ? in_array($field, $this->field) : false;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @filename CatchRepository.php
|
||||
* @createdAt 2020/6/21
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\base;
|
||||
|
||||
use app\Request;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\base;
|
||||
|
||||
use think\Validate;
|
||||
|
@@ -178,9 +178,14 @@ class CreateModuleCommand extends Command
|
||||
{
|
||||
$moduleJson = FileSystem::sharedGet(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'module.stub');
|
||||
|
||||
$content = str_replace(['{NAME}','{DESCRIPTION}','{MODULE}', '{SERVICE}'],
|
||||
[$this->name, $this->description,
|
||||
$this->module, '\\\\'. str_replace('\\', '\\\\',$this->namespaces . ucfirst($this->module) . 'Service')], $moduleJson);
|
||||
$content = str_replace(['{NAME}','{DESCRIPTION}','{MODULE}', '{SERVICE}', '{KEYWORDS}'],
|
||||
[
|
||||
$this->name, $this->description,
|
||||
$this->module,
|
||||
'\\\\'. str_replace('\\', '\\\\',
|
||||
$this->namespaces . ucfirst($this->module) . 'Service'),
|
||||
''
|
||||
], $moduleJson);
|
||||
|
||||
FileSystem::put($this->moduleDir . 'module.json', $content);
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
"alias": "{MODULE}",
|
||||
"description": "{DESCRIPTION}",
|
||||
"version": "1.0.0",
|
||||
"keywords": [],
|
||||
"keywords": [{KEYWORDS}],
|
||||
"order": 0,
|
||||
"services": [
|
||||
"{SERVICE}"
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\exceptions;
|
||||
|
||||
use Exception;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\exceptions;
|
||||
|
||||
use catcher\Code;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\exceptions;
|
||||
|
||||
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\exceptions;
|
||||
|
||||
use catcher\Code;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\exceptions;
|
||||
|
||||
use catcher\Code;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\exceptions;
|
||||
|
||||
use catcher\Code;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @filename WechatResponseException.php
|
||||
* @createdAt 2020/6/21
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\facade;
|
||||
|
||||
use think\Facade;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\facade;
|
||||
|
||||
use think\Facade;
|
||||
|
205
extend/catcher/generate/CreateModule.php
Normal file
205
extend/catcher/generate/CreateModule.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
namespace catcher\generate;
|
||||
|
||||
|
||||
use catcher\CatchAdmin;
|
||||
use catcher\facade\FileSystem;
|
||||
use catcher\library\Composer;
|
||||
|
||||
class CreateModule
|
||||
{
|
||||
protected $module;
|
||||
|
||||
protected $moduleDir;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $stubDir;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $namespaces;
|
||||
|
||||
protected $name;
|
||||
|
||||
protected $description;
|
||||
|
||||
protected $dirs;
|
||||
|
||||
protected $keywords;
|
||||
|
||||
public function generate($params)
|
||||
{
|
||||
try {
|
||||
$this->module = $params['alias'];
|
||||
|
||||
$this->name = $params['name'];
|
||||
|
||||
$this->description = $params['description'] ?? '';
|
||||
|
||||
$this->keywords = $params['keywords'] ?? '';
|
||||
|
||||
$this->dirs = $params['dirs'];
|
||||
|
||||
$this->init();
|
||||
|
||||
} catch (\Exception $exception) {
|
||||
$this->rollback();
|
||||
dd($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->moduleDir = CatchAdmin::moduleDirectory($this->module);
|
||||
|
||||
$this->stubDir =dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'command'.DIRECTORY_SEPARATOR.
|
||||
'stubs' . DIRECTORY_SEPARATOR;
|
||||
|
||||
$psr4 = (new Composer())->psr4Autoload();
|
||||
|
||||
foreach ($psr4 as $namespace => $des) {
|
||||
if ($des === CatchAdmin::$root) {
|
||||
$this->namespaces = $namespace . $this->module . '\\';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->createFile();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 模块文件
|
||||
*
|
||||
* @time 2020年06月25日
|
||||
* @return string[]
|
||||
*/
|
||||
protected function moduleFiles()
|
||||
{
|
||||
return [
|
||||
$this->moduleDir . ucfirst($this->module). 'Service.php',
|
||||
$this->moduleDir . 'module.json',
|
||||
$this->moduleDir . 'route.php',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建失败 rollback
|
||||
*
|
||||
* @time 2020年06月25日
|
||||
* @return void
|
||||
*/
|
||||
protected function rollback()
|
||||
{
|
||||
FileSystem::deleteDirectory($this->moduleDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* 模块文件夹
|
||||
*
|
||||
* @time 2020年06月25日
|
||||
* @return string[]
|
||||
*/
|
||||
protected function modulePath()
|
||||
{
|
||||
|
||||
$dirs = [];
|
||||
foreach (explode(',', $this->dirs) as $dir) {
|
||||
if ($dir == 'database') {
|
||||
$dirs[] = $this->moduleDir . 'database' . DIRECTORY_SEPARATOR . 'migrations';
|
||||
$dirs[] = $this->moduleDir . 'database' . DIRECTORY_SEPARATOR . 'seeds';
|
||||
} else {
|
||||
$dirs[] = $this->moduleDir . $dir;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建路径
|
||||
*
|
||||
* @time 2020年06月25日
|
||||
* @return void
|
||||
*/
|
||||
protected function createDir()
|
||||
{
|
||||
foreach ($this->modulePath() as $path)
|
||||
{
|
||||
CatchAdmin::makeDirectory($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件
|
||||
*
|
||||
* @time 2020年06月25日
|
||||
* @return void
|
||||
*/
|
||||
protected function createFile()
|
||||
{
|
||||
$this->createDir();
|
||||
$this->createService();
|
||||
$this->createRoute();
|
||||
$this->createModuleJson();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 service
|
||||
*
|
||||
* @time 2020年06月25日
|
||||
* @return void
|
||||
*/
|
||||
protected function createService()
|
||||
{
|
||||
$service = FileSystem::sharedGet($this->stubDir . 'service.stub');
|
||||
|
||||
$content = str_replace(['{NAMESPACE}', '{SERVICE}'],
|
||||
[substr($this->namespaces, 0, -1),
|
||||
ucfirst($this->module) . 'Service'], $service);
|
||||
|
||||
FileSystem::put($this->moduleDir . ucfirst($this->module) . 'Service.php', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 module.json
|
||||
*
|
||||
* @time 2020年06月25日
|
||||
* @return void
|
||||
*/
|
||||
protected function createModuleJson()
|
||||
{
|
||||
$moduleJson = FileSystem::sharedGet( $this->stubDir . 'module.stub');
|
||||
|
||||
$keywords = '';
|
||||
foreach (explode(',',$this->keywords) as $k) {
|
||||
$keywords .= "\"{$k}\",";
|
||||
}
|
||||
|
||||
$content = str_replace(['{NAME}','{DESCRIPTION}','{MODULE}', '{KEYWORDS}','{SERVICE}'],
|
||||
[
|
||||
$this->name,
|
||||
$this->description,
|
||||
$this->module,
|
||||
trim($keywords, ','),
|
||||
'\\\\'. str_replace('\\', '\\\\',$this->namespaces . ucfirst($this->module) . 'Service')
|
||||
], $moduleJson);
|
||||
|
||||
FileSystem::put($this->moduleDir . 'module.json', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建路由文件
|
||||
*
|
||||
* @time 2020年06月25日
|
||||
* @return void
|
||||
*/
|
||||
protected function createRoute()
|
||||
{
|
||||
FileSystem::put($this->moduleDir . 'route.php', FileSystem::sharedGet($this->stubDir . 'route.stub'));
|
||||
}
|
||||
}
|
@@ -8,10 +8,14 @@ use catcher\generate\factory\Migration;
|
||||
use catcher\generate\factory\Model;
|
||||
use catcher\generate\factory\Route;
|
||||
use catcher\generate\factory\SQL;
|
||||
use catcher\library\Composer;
|
||||
use think\facade\Db;
|
||||
|
||||
class Generator
|
||||
{
|
||||
|
||||
const NEED_PACKAGE = 'nikic/php-parser';
|
||||
|
||||
/**
|
||||
* generate
|
||||
*
|
||||
@@ -21,6 +25,13 @@ class Generator
|
||||
*/
|
||||
public function done($params)
|
||||
{
|
||||
// 判断是否安装了扩展包
|
||||
if (!(new Composer)->hasPackage(self::NEED_PACKAGE)) {
|
||||
throw new FailedException(
|
||||
sprintf('you must use [ composer require --dev %s]', self::NEED_PACKAGE)
|
||||
);
|
||||
}
|
||||
|
||||
$params = \json_decode($params['data'], true);
|
||||
|
||||
[$controller, $model] = $this->parseParams($params);
|
||||
|
141
extend/catcher/generate/build/CatchBuild.php
Normal file
141
extend/catcher/generate/build/CatchBuild.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
namespace catcher\generate\build;
|
||||
|
||||
use catcher\CatchAdmin;
|
||||
use catcher\facade\FileSystem;
|
||||
use catcher\generate\build\classes\Classes;
|
||||
use PhpParser\BuilderFactory;
|
||||
use PhpParser\PrettyPrinter\Standard;
|
||||
|
||||
class CatchBuild
|
||||
{
|
||||
protected $astBuilder;
|
||||
|
||||
protected $outPath;
|
||||
|
||||
protected $filename;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->astBuilder = app(BuilderFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 命名空间
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @param string $namespace
|
||||
* @return $this
|
||||
*/
|
||||
public function namespace(string $namespace)
|
||||
{
|
||||
$this->astBuilder = $this->astBuilder->namespace($namespace);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* use 方法体
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @param $use
|
||||
* @return $this
|
||||
*/
|
||||
public function use($use)
|
||||
{
|
||||
$this->astBuilder->addStmt($use);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* class 模版
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @param Classes $class
|
||||
* @param \Closure $function
|
||||
* @return $this
|
||||
*/
|
||||
public function class(Classes $class, \Closure $function)
|
||||
{
|
||||
$function($class);
|
||||
|
||||
$this->astBuilder->addStmt($class->build());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 条件
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @param $condition
|
||||
* @param \Closure $closure
|
||||
* @return $this
|
||||
*/
|
||||
public function when($condition, \Closure $closure)
|
||||
{
|
||||
if ($condition && $closure instanceof \Closure) {
|
||||
$closure($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内容
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
$stmts = array($this->astBuilder->getNode());
|
||||
|
||||
$prettyPrinter = new Standard();
|
||||
|
||||
return $prettyPrinter->prettyPrintFile($stmts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @return string
|
||||
*/
|
||||
public function output()
|
||||
{
|
||||
return FileSystem::put($this->outPath . $this->filename, $this->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出 Path
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @param $path
|
||||
* @return $this
|
||||
*/
|
||||
public function path($path)
|
||||
{
|
||||
CatchAdmin::makeDirectory($path);
|
||||
|
||||
$this->outPath = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文件名
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @param $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function filename($name)
|
||||
{
|
||||
$this->filename = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
117
extend/catcher/generate/build/classes/Classes.php
Normal file
117
extend/catcher/generate/build/classes/Classes.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
namespace catcher\generate\build\classes;
|
||||
|
||||
use PhpParser\BuilderFactory;
|
||||
|
||||
class Classes
|
||||
{
|
||||
protected $classBuild;
|
||||
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->classBuild = (new BuilderFactory())->class($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 comment
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @param string $comment
|
||||
* @return $this
|
||||
*/
|
||||
public function docComment($comment="\r\n")
|
||||
{
|
||||
$this->classBuild->setDocComment($comment);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @time 2020年11月17日
|
||||
* @param $extend
|
||||
* @return $this
|
||||
*/
|
||||
public function extend($extend)
|
||||
{
|
||||
$this->classBuild->extend($extend);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @time 2020年11月17日
|
||||
* @param $interfaces
|
||||
* @return $this
|
||||
*/
|
||||
public function implement($interfaces)
|
||||
{
|
||||
$this->classBuild->implement($interfaces);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @time 2020年11月17日
|
||||
* @return $this
|
||||
*/
|
||||
public function abstract()
|
||||
{
|
||||
$this->classBuild->makeAbstract();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @time 2020年11月17日
|
||||
* @return $this
|
||||
*/
|
||||
public function final()
|
||||
{
|
||||
$this->classBuild->makeFinal();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
return $this->classBuild;
|
||||
}
|
||||
|
||||
public function addMethod(Methods $method)
|
||||
{
|
||||
$this->classBuild->addStmt($method->build());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addProperty(Property $property)
|
||||
{
|
||||
$this->classBuild->addStmt($property->build());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addTrait(Traits $trait)
|
||||
{
|
||||
$this->classBuild->addStmt($trait->build());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* when
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @param $condition
|
||||
* @param \Closure $closure
|
||||
* @return $this
|
||||
*/
|
||||
public function when($condition, \Closure $closure)
|
||||
{
|
||||
if ($condition) {
|
||||
$closure($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
158
extend/catcher/generate/build/classes/Methods.php
Normal file
158
extend/catcher/generate/build/classes/Methods.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
namespace catcher\generate\build\classes;
|
||||
|
||||
use catcher\generate\build\traits\CatchMethodReturn;
|
||||
use PhpParser\BuilderFactory;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
|
||||
class Methods
|
||||
{
|
||||
|
||||
use CatchMethodReturn;
|
||||
|
||||
protected $methodBuild;
|
||||
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->methodBuild = (new BuilderFactory())->method($name);
|
||||
}
|
||||
|
||||
public function public()
|
||||
{
|
||||
$this->methodBuild->makePublic();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function protected()
|
||||
{
|
||||
$this->methodBuild->makeProtected();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function private()
|
||||
{
|
||||
$this->methodBuild->makePrivate();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* set params
|
||||
*
|
||||
* @time 2020年11月16日
|
||||
* @param $type
|
||||
* @param $param
|
||||
* @param $default
|
||||
* @return $this
|
||||
*/
|
||||
public function param($param, $type = null, $default = null)
|
||||
{
|
||||
$param = (new BuilderFactory())->param($param);
|
||||
|
||||
if ($type) {
|
||||
$param = $param->setType($type);
|
||||
}
|
||||
|
||||
if ($default) {
|
||||
$param = $param->setDefault($default);
|
||||
}
|
||||
|
||||
$this->methodBuild->addParam(
|
||||
$param
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义
|
||||
*
|
||||
* @time 2020年11月18日
|
||||
* @param $variable
|
||||
* @param $value
|
||||
* @return $this
|
||||
*/
|
||||
public function declare($variable, $value)
|
||||
{
|
||||
$smt = new Expression(
|
||||
new Assign(
|
||||
new PropertyFetch(
|
||||
new Variable('this'),
|
||||
new Identifier($variable)
|
||||
),
|
||||
new Variable($value)
|
||||
)
|
||||
);
|
||||
|
||||
$this->methodBuild->addStmt($smt);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回值
|
||||
*
|
||||
* @time 2020年11月16日
|
||||
* @param $returnType
|
||||
* @return $this
|
||||
*/
|
||||
public function returnType($returnType)
|
||||
{
|
||||
$this->methodBuild->setReturnType($returnType);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 注释
|
||||
*
|
||||
* @time 2020年11月16日
|
||||
* @param $comment
|
||||
* @return $this
|
||||
*/
|
||||
public function docComment(string $comment)
|
||||
{
|
||||
$this->methodBuild->setDocComment($comment);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽象
|
||||
*
|
||||
* @time 2020年11月17日
|
||||
* @return $this
|
||||
*/
|
||||
public function toAbstract()
|
||||
{
|
||||
$this->methodBuild->makeAbstract();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* final
|
||||
*
|
||||
* @time 2020年11月17日
|
||||
* @return $this
|
||||
*/
|
||||
public function toFinal()
|
||||
{
|
||||
$this->methodBuild->makeFinal();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function build()
|
||||
{
|
||||
return $this->methodBuild;
|
||||
}
|
||||
}
|
97
extend/catcher/generate/build/classes/Property.php
Normal file
97
extend/catcher/generate/build/classes/Property.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
namespace catcher\generate\build\classes;
|
||||
|
||||
use PhpParser\BuilderFactory;
|
||||
|
||||
class Property
|
||||
{
|
||||
protected $propertyBuild;
|
||||
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->propertyBuild = (new BuilderFactory())->property($name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @time 2020年11月17日
|
||||
* @return $this
|
||||
*/
|
||||
public function public()
|
||||
{
|
||||
$this->propertyBuild->makePublic();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @time 2020年11月17日
|
||||
* @return $this
|
||||
*/
|
||||
public function protected()
|
||||
{
|
||||
$this->propertyBuild->makeProtected();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @time 2020年11月17日
|
||||
* @return $this
|
||||
*/
|
||||
public function private()
|
||||
{
|
||||
$this->propertyBuild->makePrivate();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注释
|
||||
*
|
||||
* @time 2020年11月16日
|
||||
* @param $comment
|
||||
* @return $this
|
||||
*/
|
||||
public function static($comment)
|
||||
{
|
||||
$this->propertyBuild->makeStatic();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set default
|
||||
*
|
||||
* @time 2020年11月16日
|
||||
* @param $value
|
||||
* @return $this
|
||||
*/
|
||||
public function default($value)
|
||||
{
|
||||
$this->propertyBuild->setDefault($value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function type($type)
|
||||
{
|
||||
$this->propertyBuild->setType($type);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function docComment($comment)
|
||||
{
|
||||
$this->propertyBuild->setDocComment($comment);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
return $this->propertyBuild;
|
||||
}
|
||||
}
|
88
extend/catcher/generate/build/classes/Traits.php
Normal file
88
extend/catcher/generate/build/classes/Traits.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace catcher\generate\build\classes;
|
||||
|
||||
use PhpParser\BuilderFactory;
|
||||
|
||||
class Traits
|
||||
{
|
||||
protected $traitBuild;
|
||||
|
||||
protected $build;
|
||||
|
||||
public function use(...$names)
|
||||
{
|
||||
$this->build = new BuilderFactory;
|
||||
|
||||
$this->traitBuild = call_user_func_array([$this->build, 'useTrait'], $names);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function and($name)
|
||||
{
|
||||
$this->traitBuild->and($name);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* with
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @param \Closure|null $closure
|
||||
* @return $this
|
||||
*/
|
||||
public function with(\Closure $closure = null)
|
||||
{
|
||||
if ($closure instanceof \Closure) {
|
||||
$this->traitBuild->withe($closure($this));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @time 2020年11月19日
|
||||
* @param $name
|
||||
* @param null $method
|
||||
* @return $this
|
||||
*/
|
||||
public function adaptation($name, $method = null)
|
||||
{
|
||||
$this->build = $this->build->traitUseAdaptation($name. $method);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @time 2020年11月19日
|
||||
* @param $name
|
||||
* @return $this
|
||||
*/
|
||||
public function as($name)
|
||||
{
|
||||
$this->build->as($name);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @time 2020年11月19日
|
||||
* @param $name
|
||||
* @return $this
|
||||
*/
|
||||
public function insteadof($name)
|
||||
{
|
||||
$this->build->insteadof($name);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
return $this->traitBuild;
|
||||
}
|
||||
}
|
29
extend/catcher/generate/build/classes/Uses.php
Normal file
29
extend/catcher/generate/build/classes/Uses.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace catcher\generate\build\classes;
|
||||
|
||||
use PhpParser\BuilderFactory;
|
||||
|
||||
class Uses
|
||||
{
|
||||
public function name(string $name, string $as = '')
|
||||
{
|
||||
$build = (new BuilderFactory())->use($name);
|
||||
|
||||
if ($as) {
|
||||
$build->as($as);
|
||||
}
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
public function function(string $function)
|
||||
{
|
||||
return (new BuilderFactory())->useFunction($function);
|
||||
}
|
||||
|
||||
public function const(string $const)
|
||||
{
|
||||
return (new BuilderFactory())->useConst($const);
|
||||
}
|
||||
}
|
130
extend/catcher/generate/build/traits/CatchMethodReturn.php
Normal file
130
extend/catcher/generate/build/traits/CatchMethodReturn.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
namespace catcher\generate\build\traits;
|
||||
|
||||
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
|
||||
trait CatchMethodReturn
|
||||
{
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @time 2020年11月18日
|
||||
* @param $model
|
||||
* @return $this
|
||||
*/
|
||||
public function index($model)
|
||||
{
|
||||
$class = new Name('CatchResponse');
|
||||
|
||||
$arg = new Arg(new MethodCall(
|
||||
new PropertyFetch(
|
||||
new Variable('this'), new Identifier($model)
|
||||
),
|
||||
new Identifier('getList')
|
||||
));
|
||||
|
||||
$this->methodBuild->addStmt(new Return_(new StaticCall($class, 'paginate', [$arg])));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*
|
||||
* @time 2020年11月18日
|
||||
* @param $model
|
||||
* @return $this
|
||||
*/
|
||||
public function save($model)
|
||||
{
|
||||
$arg = new Arg(new MethodCall(
|
||||
new PropertyFetch(
|
||||
new Variable('this'), new Identifier($model)
|
||||
),
|
||||
new Identifier('storeBy'), [new Arg(new MethodCall(new Variable('request'), new Identifier('post')))]
|
||||
));
|
||||
|
||||
$class = new Name('CatchResponse');
|
||||
|
||||
$this->methodBuild->addStmt(new Return_(new StaticCall($class, 'success', [$arg])));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @time 2020年11月18日
|
||||
* @param $model
|
||||
* @return $this
|
||||
*/
|
||||
public function update($model)
|
||||
{
|
||||
$arg = new Arg(new MethodCall(
|
||||
new PropertyFetch(
|
||||
new Variable('this'), new Identifier($model)
|
||||
),
|
||||
new Identifier('updateBy'), [
|
||||
new Arg(new Variable('id')),
|
||||
new Arg(new MethodCall(new Variable('request'), new Identifier('post')))
|
||||
]
|
||||
));
|
||||
|
||||
$class = new Name('CatchResponse');
|
||||
|
||||
$this->methodBuild->addStmt(new Return_(new StaticCall($class, 'success', [$arg])));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function read($model)
|
||||
{
|
||||
$arg = new Arg(new MethodCall(
|
||||
new PropertyFetch(
|
||||
new Variable('this'), new Identifier($model)
|
||||
),
|
||||
new Identifier('findBy'), [
|
||||
new Arg(new Variable('id'))
|
||||
]
|
||||
));
|
||||
|
||||
$class = new Name('CatchResponse');
|
||||
|
||||
$this->methodBuild->addStmt(new Return_(new StaticCall($class, 'success', [$arg])));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @time 2020年11月18日
|
||||
* @param $model
|
||||
* @return $this
|
||||
*/
|
||||
public function delete($model)
|
||||
{
|
||||
$arg = new Arg(new MethodCall(
|
||||
new PropertyFetch(
|
||||
new Variable('this'), new Identifier($model)
|
||||
),
|
||||
new Identifier('deleteBy'), [
|
||||
new Arg(new Variable('id'))
|
||||
]
|
||||
));
|
||||
|
||||
$class = new Name('CatchResponse');
|
||||
|
||||
$this->methodBuild->addStmt(new Return_(new StaticCall($class, 'success', [$arg])));
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
28
extend/catcher/generate/build/types/Arr.php
Normal file
28
extend/catcher/generate/build/types/Arr.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace catcher\generate\build\types;
|
||||
|
||||
use PhpParser\Comment\Doc;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
|
||||
class Arr
|
||||
{
|
||||
public function build($fields)
|
||||
{
|
||||
$items = [];
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$arrItem = new ArrayItem(new String_($field['name']));
|
||||
if ($field['comment']) {
|
||||
$arrItem->setDocComment(
|
||||
new Doc('// ' . $field['comment'])
|
||||
);
|
||||
}
|
||||
$items[] = $arrItem;
|
||||
|
||||
}
|
||||
|
||||
return new Array_($items);
|
||||
}
|
||||
}
|
@@ -1,14 +1,35 @@
|
||||
<?php
|
||||
namespace catcher\generate\factory;
|
||||
|
||||
use catcher\CatchAdmin;
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\generate\template\Controller as Template;
|
||||
use catcher\facade\FileSystem;
|
||||
use catcher\generate\build\classes\Methods;
|
||||
use catcher\generate\build\CatchBuild;
|
||||
use catcher\generate\build\classes\Classes;
|
||||
use catcher\generate\build\classes\Property;
|
||||
use catcher\generate\build\classes\Uses;
|
||||
use PhpParser\BuilderFactory;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\ClosureUse;
|
||||
use PhpParser\PrettyPrinter\Standard;
|
||||
use think\helper\Str;
|
||||
use PhpParser\Error;
|
||||
use PhpParser\NodeDumper;
|
||||
use PhpParser\ParserFactory;
|
||||
use PhpParser\PrettyPrinter;
|
||||
use PhpParser\Node;
|
||||
|
||||
class Controller extends Factory
|
||||
{
|
||||
protected $methods = [];
|
||||
|
||||
protected $uses = [
|
||||
'catcher\base\CatchRequest as Request',
|
||||
'catcher\CatchResponse',
|
||||
'catcher\base\CatchController'
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2020年04月27日
|
||||
@@ -19,7 +40,8 @@ class Controller extends Factory
|
||||
{
|
||||
// 写入成功之后
|
||||
$controllerPath = $this->getGeneratePath($params['controller']);
|
||||
if (file_put_contents($controllerPath, $this->getContent($params))) {
|
||||
|
||||
if (FileSystem::put($controllerPath, $this->getContent($params))) {
|
||||
return $controllerPath;
|
||||
}
|
||||
|
||||
@@ -39,109 +61,135 @@ class Controller extends Factory
|
||||
throw new FailedException('params has lost~');
|
||||
}
|
||||
|
||||
$template = new Template();
|
||||
// parse controller
|
||||
[$className, $namespace] = $this->parseFilename($params['controller']);
|
||||
|
||||
[$model, $modelNamespace] = $this->parseFilename($params['model']);
|
||||
|
||||
$asModel = lcfirst(Str::contains($model, 'Model') ? : $model . 'Model');
|
||||
|
||||
if (!$className) {
|
||||
throw new FailedException('未填写控制器名称');
|
||||
}
|
||||
|
||||
// parse model
|
||||
[$model, $modelNamespace] = $this->parseFilename($params['model']);
|
||||
$use = new Uses();
|
||||
$class = new Classes($className);
|
||||
|
||||
$use = implode(';',[
|
||||
'use ' . $params['model'] .' as '. $model . 'Model',
|
||||
]) . ';';
|
||||
|
||||
$content = $template->header() .
|
||||
$template->nameSpace($namespace) .
|
||||
str_replace('{USE}', $model ? $use : '', $template->uses()) .
|
||||
$template->createClass($className);
|
||||
|
||||
return str_replace('{CONTENT}', ($model ? $template->construct($model.'Model') : '') . rtrim($this->content($params, $template), "\r\n"), $content);
|
||||
return (new CatchBuild())->namespace($namespace)
|
||||
->use($use->name('catcher\base\CatchRequest', 'Request'))
|
||||
->use($use->name('catcher\CatchResponse'))
|
||||
->use($use->name('catcher\base\CatchController'))
|
||||
->use($use->name($modelNamespace . '\\' . ucfirst($model), $asModel))
|
||||
->class($class->extend('CatchController')->docComment(), function (Classes $class) use ($asModel) {
|
||||
foreach ($this->getMethods($asModel) as $method) {
|
||||
$class->addMethod($method);
|
||||
}
|
||||
|
||||
$class->addProperty(
|
||||
(new Property($asModel))->protected()
|
||||
);
|
||||
})
|
||||
->getContent();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* parse use
|
||||
* 方法集合
|
||||
*
|
||||
* @time 2020年04月28日
|
||||
* @param $params
|
||||
* @return string
|
||||
* @time 2020年11月19日
|
||||
* @param $model
|
||||
* @return array
|
||||
*/
|
||||
protected function parseUse($params)
|
||||
protected function getMethods($model)
|
||||
{
|
||||
$date = date('Y年m月d日 H:i');
|
||||
|
||||
}
|
||||
/**
|
||||
* content
|
||||
*
|
||||
* @time 2020年04月27日
|
||||
* @param $params
|
||||
* @param $template
|
||||
* @return string
|
||||
*/
|
||||
protected function content($params, $template)
|
||||
{
|
||||
$content = '';
|
||||
|
||||
if ($params['restful']) {
|
||||
$methods = $this->restful();
|
||||
$this->methods = array_merge($this->methods, $methods);
|
||||
foreach ($methods as $method) {
|
||||
$content .= $template->{$method[0]}();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
if (!empty($params['other_function'])) {
|
||||
$others = $this->parseOtherMethods($params['other_function']);
|
||||
$this->methods = array_merge($this->methods, $others);
|
||||
foreach ($others as $other) {
|
||||
$content .= $template->otherFunction($other[0], $other[1]);
|
||||
}
|
||||
}*/
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse $method
|
||||
* class_method/http_method
|
||||
* @time 2020年04月27日
|
||||
* @param $methods
|
||||
* @return false|string[]
|
||||
*/
|
||||
public function parseOtherMethods($methods)
|
||||
{
|
||||
$_methods = [];
|
||||
|
||||
foreach ($methods as $method) {
|
||||
if (Str::contains($method, '/')) {
|
||||
$_methods[] = explode('/', $method);
|
||||
} else {
|
||||
// 默认使用 Get 方式
|
||||
$_methods[] = [$method, 'get'];
|
||||
}
|
||||
}
|
||||
|
||||
return $_methods;
|
||||
}
|
||||
|
||||
/**
|
||||
* restful 路由
|
||||
*
|
||||
* @time 2020年04月27日
|
||||
* @return \string[][]
|
||||
*/
|
||||
public function restful()
|
||||
{
|
||||
return [
|
||||
['index', 'get'],
|
||||
['save', 'post'],
|
||||
['read', 'get'],
|
||||
['update', 'put'],
|
||||
['delete', 'delete'],
|
||||
(new Methods('__construct'))
|
||||
->public()
|
||||
->param($model, ucfirst($model))
|
||||
->docComment("\r\n")
|
||||
->declare($model, $model),
|
||||
|
||||
(new Methods('index'))->public()
|
||||
->param('request', 'Request')
|
||||
->docComment(
|
||||
<<<TEXT
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @time $date
|
||||
* @param Request \$request
|
||||
*/
|
||||
TEXT
|
||||
)
|
||||
->returnType('\think\Response')->index($model),
|
||||
|
||||
(new Methods('save'))
|
||||
->public()
|
||||
->param('request', 'Request')
|
||||
->docComment(
|
||||
<<<TEXT
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
* @time $date
|
||||
* @param Request \$request
|
||||
*/
|
||||
TEXT
|
||||
)
|
||||
->returnType('\think\Response')
|
||||
->save($model),
|
||||
|
||||
|
||||
(new Methods('read'))->public()
|
||||
->param('id')
|
||||
->docComment(
|
||||
<<<TEXT
|
||||
|
||||
/**
|
||||
* 读取
|
||||
* @time $date
|
||||
* @param \$id
|
||||
*/
|
||||
TEXT
|
||||
|
||||
)
|
||||
->returnType('\think\Response')->read($model),
|
||||
|
||||
|
||||
(new Methods('update'))->public()
|
||||
->param('request', 'Request')
|
||||
->param('id')
|
||||
->docComment(
|
||||
<<<TEXT
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @time $date
|
||||
* @param Request \$request
|
||||
* @param \$id
|
||||
*/
|
||||
TEXT
|
||||
)
|
||||
->returnType('\think\Response')->update($model),
|
||||
|
||||
|
||||
(new Methods('delete'))->public()
|
||||
->param('id')
|
||||
->docComment(
|
||||
<<<TEXT
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @time $date
|
||||
* @param \$id
|
||||
*/
|
||||
TEXT
|
||||
)
|
||||
->returnType('\think\Response')->delete($model),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -42,7 +42,7 @@ abstract class Factory
|
||||
|
||||
CatchAdmin::makeDirectory($filePath);
|
||||
|
||||
return $filePath . DIRECTORY_SEPARATOR . $filename . '.php';
|
||||
return $filePath . DIRECTORY_SEPARATOR . ucfirst($filename ). '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -2,21 +2,35 @@
|
||||
namespace catcher\generate\factory;
|
||||
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\generate\template\Model as Template;
|
||||
use catcher\facade\FileSystem;
|
||||
use catcher\generate\build\CatchBuild;
|
||||
use catcher\generate\build\classes\Classes;
|
||||
use catcher\generate\build\classes\Property;
|
||||
use catcher\generate\build\classes\Traits;
|
||||
use catcher\generate\build\classes\Uses;
|
||||
use catcher\generate\build\types\Arr;
|
||||
use catcher\traits\db\BaseOptionsTrait;
|
||||
use catcher\traits\db\ScopeTrait;
|
||||
use catcher\Utils;
|
||||
use Phinx\Util\Util;
|
||||
use think\facade\Db;
|
||||
use think\helper\Str;
|
||||
|
||||
class Model extends Factory
|
||||
{
|
||||
/**
|
||||
* done
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @param $params
|
||||
* @return string
|
||||
*/
|
||||
public function done($params)
|
||||
{
|
||||
$content = $this->getContent($params);
|
||||
|
||||
$modelPath = $this->getGeneratePath($params['model']);
|
||||
|
||||
file_put_contents($modelPath, $content);
|
||||
FileSystem::put($modelPath, $content);
|
||||
|
||||
if (!file_exists($modelPath)) {
|
||||
throw new FailedException('create model failed');
|
||||
@@ -34,9 +48,6 @@ class Model extends Factory
|
||||
*/
|
||||
public function getContent($params)
|
||||
{
|
||||
// TODO: Implement done() method.
|
||||
$template = new Template();
|
||||
|
||||
$extra = $params['extra'];
|
||||
|
||||
$table = $params['table'];
|
||||
@@ -53,43 +64,35 @@ class Model extends Factory
|
||||
throw new FailedException('model name not set');
|
||||
}
|
||||
|
||||
$content = $template->useTrait($extra['soft_delete']) .
|
||||
$template->name(str_replace(Utils::tablePrefix(), '', $table)) .
|
||||
$template->field($this->parseField($table));
|
||||
$softDelete = $extra['soft_delete'];
|
||||
|
||||
$class = $template->header() .
|
||||
$template->nameSpace($namespace) .
|
||||
$template->uses($extra['soft_delete']) .
|
||||
$template->createModel($modelName, $table);
|
||||
|
||||
return str_replace('{CONTENT}', $content, $class);
|
||||
return (new CatchBuild)->namespace($namespace)
|
||||
->use((new Uses())->name('catcher\base\CatchModel', 'Model'))
|
||||
->when(!$softDelete, function (CatchBuild $build){
|
||||
$build->use((new Uses())->name(BaseOptionsTrait::class));
|
||||
$build->use((new Uses())->name(ScopeTrait::class));
|
||||
})
|
||||
->class((new Classes($modelName))->extend('Model')->docComment(),
|
||||
function (Classes $class) use ($softDelete, $table) {
|
||||
if (!$softDelete) {
|
||||
$class->addTrait(
|
||||
(new Traits())->use('BaseOptionsTrait', 'ScopeTrait')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* parse field
|
||||
*
|
||||
* @time 2020年04月28日
|
||||
* @param $table
|
||||
* @return string
|
||||
*/
|
||||
protected function parseField($table)
|
||||
{
|
||||
if (!$this->hasTableExists($table)) {
|
||||
return false;
|
||||
}
|
||||
$class->addProperty(
|
||||
(new Property('name'))->default(
|
||||
Utils::tableWithoutPrefix($table)
|
||||
)->docComment('// 表名')
|
||||
);
|
||||
|
||||
$columns = Db::query('show full columns from ' . $table);
|
||||
$class->when($this->hasTableExists($table), function ($class) use ($table){
|
||||
$class->addProperty(
|
||||
(new Property('field'))->default(
|
||||
(new Arr)->build(Db::getFields($table))
|
||||
)->docComment('// 数据库字段映射'));
|
||||
});
|
||||
|
||||
$new = [];
|
||||
foreach ($columns as $field) {
|
||||
$new[$field['Field']] = $field['Comment'];
|
||||
}
|
||||
|
||||
$fields = [];
|
||||
foreach ($new as $field => $comment) {
|
||||
$fields[] = sprintf("'%s', // %s", $field, $comment);
|
||||
}
|
||||
|
||||
return implode("\r\n\t\t", $fields);
|
||||
})->getContent();
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace catcher\generate\factory;
|
||||
|
||||
use catcher\facade\FileSystem;
|
||||
use catcher\generate\template\Content;
|
||||
|
||||
class Route extends Factory
|
||||
@@ -34,11 +35,12 @@ class Route extends Factory
|
||||
$comment = '// ' . $this->controllerName . '路由';
|
||||
|
||||
array_unshift($route, $comment);
|
||||
|
||||
if (file_exists($router)) {
|
||||
return file_put_contents($router, $this->parseRoute($router, $route));
|
||||
return FileSystem::put($router, $this->parseRoute($router, $route));
|
||||
}
|
||||
|
||||
return file_put_contents($router, $this->header() . $comment. implode(';'. PHP_EOL , $route) . ';');
|
||||
return FileSystem::put($router, $this->header() . $comment. implode(';'. PHP_EOL , $route) . ';');
|
||||
}
|
||||
|
||||
protected function parseRoute($path, $route)
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
@@ -14,22 +16,71 @@ use catcher\facade\FileSystem;
|
||||
|
||||
class Composer
|
||||
{
|
||||
/**
|
||||
* psr4
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @return mixed
|
||||
*/
|
||||
public function psr4Autoload()
|
||||
{
|
||||
return $this->composerContent()['autoload']['psr-4'];
|
||||
return $this->content()['autoload']['psr-4'];
|
||||
}
|
||||
|
||||
/**
|
||||
* require
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @return mixed
|
||||
*/
|
||||
public function requires()
|
||||
{
|
||||
return $this->composerContent()['require'];
|
||||
return $this->content()['require'];
|
||||
}
|
||||
|
||||
protected function composerContent()
|
||||
/**
|
||||
* require dev
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @return mixed
|
||||
*/
|
||||
public function requireDev()
|
||||
{
|
||||
return \json_decode(FileSystem::get($this->composerJsonPath()), true);
|
||||
return $this->content()['require-dev'];
|
||||
}
|
||||
|
||||
protected function composerJsonPath()
|
||||
/**
|
||||
* composer has package
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @param $name
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPackage($name)
|
||||
{
|
||||
$packages = array_merge($this->requires(), $this->requireDev());
|
||||
|
||||
return in_array($name, array_keys($packages));
|
||||
}
|
||||
|
||||
/**
|
||||
* composer content
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @return mixed
|
||||
*/
|
||||
protected function content()
|
||||
{
|
||||
return \json_decode(FileSystem::sharedGet($this->path()), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* composer path
|
||||
*
|
||||
* @time 2020年11月19日
|
||||
* @return string
|
||||
*/
|
||||
protected function path()
|
||||
{
|
||||
return root_path() . 'composer.json';
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library;
|
||||
|
||||
use catcher\CatchAdmin;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @filename Errors.php
|
||||
* @createdAt 2020/6/21
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace catcher\library;
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library;
|
||||
|
||||
use think\exception\ClassNotFoundException;
|
||||
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @filename ProgressBar.php
|
||||
* @createdAt 2020/6/20
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library;
|
||||
|
||||
use catcher\CatchCacheKeys;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @filename WeChat.php
|
||||
* @date 2020/6/7
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library\client;
|
||||
|
||||
use catcher\exceptions\FailedException;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library\client;
|
||||
|
||||
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library\excel;
|
||||
|
||||
use catcher\CatchUpload;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library\excel;
|
||||
|
||||
interface ExcelContract
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library\excel;
|
||||
|
||||
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library\excel;
|
||||
|
||||
trait MacroExcel
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library\excel;
|
||||
|
||||
interface ShouldTaskContract
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\traits\db;
|
||||
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @filename ScopeTrait.php
|
||||
* @createdAt 2020/6/21
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\traits\db;
|
||||
|
||||
use think\facade\Db;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\validates;
|
||||
|
||||
use catcher\library\Trie;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\validates;
|
||||
|
||||
class Sometimes implements ValidateInterface
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\validates;
|
||||
|
||||
interface ValidateInterface
|
||||
|
Reference in New Issue
Block a user