diff --git a/bootstrap/cache/packages.php b/bootstrap/cache/packages.php
index b6afc0a..eb8d4e0 100755
--- a/bootstrap/cache/packages.php
+++ b/bootstrap/cache/packages.php
@@ -1,4 +1,11 @@
+ array (
+ 'providers' =>
+ array (
+ 0 => 'Catch\\Providers\\CatchAdminServiceProvider',
+ ),
+ ),
'laravel/tinker' =>
array (
'providers' =>
diff --git a/bootstrap/cache/services.php b/bootstrap/cache/services.php
index ff94066..314d24c 100755
--- a/bootstrap/cache/services.php
+++ b/bootstrap/cache/services.php
@@ -23,17 +23,18 @@
19 => 'Illuminate\\Translation\\TranslationServiceProvider',
20 => 'Illuminate\\Validation\\ValidationServiceProvider',
21 => 'Illuminate\\View\\ViewServiceProvider',
- 22 => 'Laravel\\Tinker\\TinkerServiceProvider',
- 23 => 'Carbon\\Laravel\\ServiceProvider',
- 24 => 'NunoMaduro\\Collision\\Adapters\\Laravel\\CollisionServiceProvider',
- 25 => 'Termwind\\Laravel\\TermwindServiceProvider',
- 26 => 'Pest\\Laravel\\PestServiceProvider',
- 27 => 'Tymon\\JWTAuth\\Providers\\LaravelServiceProvider',
- 28 => 'Catch\\Providers\\CatchAdminServiceProvider',
- 29 => 'App\\Providers\\AppServiceProvider',
- 30 => 'App\\Providers\\AuthServiceProvider',
- 31 => 'App\\Providers\\EventServiceProvider',
- 32 => 'App\\Providers\\RouteServiceProvider',
+ 22 => 'Catch\\Providers\\CatchAdminServiceProvider',
+ 23 => 'Laravel\\Tinker\\TinkerServiceProvider',
+ 24 => 'Carbon\\Laravel\\ServiceProvider',
+ 25 => 'NunoMaduro\\Collision\\Adapters\\Laravel\\CollisionServiceProvider',
+ 26 => 'Termwind\\Laravel\\TermwindServiceProvider',
+ 27 => 'Pest\\Laravel\\PestServiceProvider',
+ 28 => 'Tymon\\JWTAuth\\Providers\\LaravelServiceProvider',
+ 29 => 'Catch\\Providers\\CatchAdminServiceProvider',
+ 30 => 'App\\Providers\\AppServiceProvider',
+ 31 => 'App\\Providers\\AuthServiceProvider',
+ 32 => 'App\\Providers\\EventServiceProvider',
+ 33 => 'App\\Providers\\RouteServiceProvider',
),
'eager' =>
array (
@@ -47,16 +48,17 @@
7 => 'Illuminate\\Pagination\\PaginationServiceProvider',
8 => 'Illuminate\\Session\\SessionServiceProvider',
9 => 'Illuminate\\View\\ViewServiceProvider',
- 10 => 'Carbon\\Laravel\\ServiceProvider',
- 11 => 'NunoMaduro\\Collision\\Adapters\\Laravel\\CollisionServiceProvider',
- 12 => 'Termwind\\Laravel\\TermwindServiceProvider',
- 13 => 'Pest\\Laravel\\PestServiceProvider',
- 14 => 'Tymon\\JWTAuth\\Providers\\LaravelServiceProvider',
- 15 => 'Catch\\Providers\\CatchAdminServiceProvider',
- 16 => 'App\\Providers\\AppServiceProvider',
- 17 => 'App\\Providers\\AuthServiceProvider',
- 18 => 'App\\Providers\\EventServiceProvider',
- 19 => 'App\\Providers\\RouteServiceProvider',
+ 10 => 'Catch\\Providers\\CatchAdminServiceProvider',
+ 11 => 'Carbon\\Laravel\\ServiceProvider',
+ 12 => 'NunoMaduro\\Collision\\Adapters\\Laravel\\CollisionServiceProvider',
+ 13 => 'Termwind\\Laravel\\TermwindServiceProvider',
+ 14 => 'Pest\\Laravel\\PestServiceProvider',
+ 15 => 'Tymon\\JWTAuth\\Providers\\LaravelServiceProvider',
+ 16 => 'Catch\\Providers\\CatchAdminServiceProvider',
+ 17 => 'App\\Providers\\AppServiceProvider',
+ 18 => 'App\\Providers\\AuthServiceProvider',
+ 19 => 'App\\Providers\\EventServiceProvider',
+ 20 => 'App\\Providers\\RouteServiceProvider',
),
'deferred' =>
array (
diff --git a/catch/config/catch.php b/catch/config/catch.php
deleted file mode 100644
index 8ea0465..0000000
--- a/catch/config/catch.php
+++ /dev/null
@@ -1,145 +0,0 @@
- [
-
- ],
-
- /*
- |--------------------------------------------------------------------------
- | catch-admin catch_auth_middleware_alias
- |--------------------------------------------------------------------------
- |
- | where you can set default middlewares
- |
- */
- 'catch_auth_middleware_alias' => [
-
- ],
-
- /*
- |--------------------------------------------------------------------------
- | catch-admin super admin id
- |--------------------------------------------------------------------------
- |
- | where you can set super admin id
- |
- */
- 'super_admin' => 1,
-
- /*
- |--------------------------------------------------------------------------
- | catch-admin module setting
- |--------------------------------------------------------------------------
- |
- | the root where module generate
- | the namespace is module root namespace
- | the default dirs is module generate default dirs
- */
- 'module' => [
- 'root' => 'modules',
-
- 'namespace' => 'Modules',
-
- 'default' => ['develop', 'user', 'permission'],
-
- 'default_dirs' => [
- 'Http'.DIRECTORY_SEPARATOR,
-
- 'Http'.DIRECTORY_SEPARATOR.'Requests'.DIRECTORY_SEPARATOR,
-
- 'Http'.DIRECTORY_SEPARATOR.'Controllers'.DIRECTORY_SEPARATOR,
-
- 'Models'.DIRECTORY_SEPARATOR,
-
- 'views'.DIRECTORY_SEPARATOR,
- ],
-
- // storage module information
- // which driver should be used?
- 'driver' => [
- // currently, catchadmin support file and database
- // the default is driver
- 'default' => 'file',
-
- // use database driver
- 'table_name' => 'admin_modules'
- ]
- ],
-
- /*
- |--------------------------------------------------------------------------
- | catch-admin response
- |--------------------------------------------------------------------------
- */
- 'response' => [
- // it's a controller middleware, it's set in CatchController
- // if you not need json response, don't extend CatchController
- 'always_json' => \Catch\Middleware\JsonResponseMiddleware::class,
-
- // response listener
- // it listens [RequestHandled] event, if you don't need this
- // you can change this config
- 'request_handled_listener' => \Catch\Listeners\RequestHandledListener::class
- ],
-
- /*
- |--------------------------------------------------------------------------
- | catch-admin auth setting
- |--------------------------------------------------------------------------
- */
- 'auth' => [
- 'guards' => [
- 'admin' => [
- 'driver' => 'jwt',
- 'provider' => 'admin_users',
- ],
- ],
-
- 'providers' => [
- 'admin_users' => [
- 'driver' => 'eloquent',
- 'model' => \Modules\User\Models\Users::class
- ]
- ]
- ],
-
- /*
- |--------------------------------------------------------------------------
- | database sql log
- |--------------------------------------------------------------------------
- */
- 'listen_db_log' => true,
-
- /*
- |--------------------------------------------------------------------------
- | route config
- |--------------------------------------------------------------------------
- */
- 'route' => [
- 'prefix' => 'api',
-
- 'middlewares' => [
- \Catch\Middleware\AuthMiddleware::class,
- \Catch\Middleware\JsonResponseMiddleware::class
- ]
- ],
-];
diff --git a/catch/database/migrations/2022_11_14_034127_module.php b/catch/database/migrations/2022_11_14_034127_module.php
deleted file mode 100644
index 4fbc5b9..0000000
--- a/catch/database/migrations/2022_11_14_034127_module.php
+++ /dev/null
@@ -1,49 +0,0 @@
-increments('id');
-
- $table->string('title')->comment('模块标题');
-
- $table->string('name')->comment('模块名称');
-
- $table->string('path', 20)->comment('模块目录');
-
- $table->string('description')->comment('模块描述');
-
- $table->string('keywords')->comment('模块关键字');
-
- $table->string('version', 20)->comment('模块版本号')->default('1.0.0');
-
- $table->boolean('status')->comment('模块状态')->default(1);
-
- $table->unsignedInteger('created_at')->comment('创建时间')->default(0);
-
- $table->unsignedInteger('updated_at')->comment('更新时间')->default(0);
- });
- }
-
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- //
- Schema::dropIfExists(config('catch.module.table_name'));
- }
-};
diff --git a/catch/src/Base/CatchController.php b/catch/src/Base/CatchController.php
deleted file mode 100644
index 54b73e7..0000000
--- a/catch/src/Base/CatchController.php
+++ /dev/null
@@ -1,42 +0,0 @@
-user();
-
- if (! $user) {
- throw new FailedException('登录失效, 请重新登录', Code::LOST_LOGIN);
- }
-
- return $user;
- }
-}
diff --git a/catch/src/Base/CatchModel.php b/catch/src/Base/CatchModel.php
deleted file mode 100644
index 325e05f..0000000
--- a/catch/src/Base/CatchModel.php
+++ /dev/null
@@ -1,89 +0,0 @@
- 'datetime:Y-m-d H:i:s',
-
- 'updated_at' => 'datetime:Y-m-d H:i:s',
-
- 'deleted_at' => 'datetime:Y-m-d H:i:s'
- ];
-
- /**
- * @var array
- */
- protected array $fieldsInList = ['*'];
-
- /**
- * @var bool
- */
- protected bool $isPaginate = true;
-
- /**
- * @var array $searchable
- */
- public array $searchable = [];
-
-
- /**
- * soft delete
- *
- * @time 2021年08月09日
- * @return void
- */
- public static function bootSoftDeletes(): void
- {
- static::addGlobalScope(new SoftDelete());
- }
-}
diff --git a/catch/src/CatchAdmin.php b/catch/src/CatchAdmin.php
deleted file mode 100644
index 90261a1..0000000
--- a/catch/src/CatchAdmin.php
+++ /dev/null
@@ -1,380 +0,0 @@
-name
- ) {
- $this->signature = $this->name.' {module}';
- }
- }
-
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- * @return void
- */
- protected function initialize(InputInterface $input, OutputInterface $output): void
- {
- if ($input->hasArgument('module')
- && ! Module::getEnabled()->pluck('name')->merge(Collection::make(config('catch.module.default')))->contains(lcfirst($input->getArgument('module')))
- ) {
- $this->error(sprintf('Module [%s] Not Found', $input->getArgument('module')));
- exit;
- }
- }
-
-
- /**
- *
- * @param string $question
- * @param null $default
- * @param bool $isChoice
- * @return string|int|null
- */
- public function askFor(string $question, $default = null, bool $isChoice = false): string|null|int
- {
- $_default = $default ? "[$default]" : '';
-
- $choice = $isChoice ? 'YesORNo' : '';
-
- $answer = ask(
- <<
-
CatchAdmin
-
- $question
- $_default
- $choice
- :
-
-
-HTML
- );
-
-
- $this->newLine();
-
- if ($default && ! $answer) {
- return $default;
- }
-
- return $answer;
- }
-
-
- /**
- * info
- *
- * @param $string
- * @param null $verbosity
- * @return void
- */
- public function info($string, $verbosity = null): void
- {
- render(
- <<
- CatchAdmin
-
- $string
-
-
-HTML
- );
- }
-
- /**
- * error
- *
- * @param $string
- * @param null $verbosity
- * @return void
- */
- public function error($string, $verbosity = null): void
- {
- render(
- <<
- CatchAdmin
-
- $string
-
-
-HTML
- );
- }
-}
diff --git a/catch/src/Commands/Create/Controller.php b/catch/src/Commands/Create/Controller.php
deleted file mode 100644
index a4c5004..0000000
--- a/catch/src/Commands/Create/Controller.php
+++ /dev/null
@@ -1,100 +0,0 @@
-argument('module'));
-
- $file = $controllerPath.$this->getControllerFile();
-
- if (File::exists($file)) {
- $answer = $this->ask($file.' already exists, Did you want replace it?', 'Y');
-
- if (! Str::of($answer)->lower()->exactly('y')) {
- exit;
- }
- }
-
- File::put($file, Str::of($this->getStubContent())->replace([
- '{namespace}', '{controller}'
- ], [trim(CatchAdmin::getModuleControllerNamespace($this->argument('module')), '\\'), $this->getControllerName()])->toString());
-
- if (File::exists($file)) {
- $this->info($file.' has been created');
- } else {
- $this->error($file.' create failed');
- }
- }
-
- /**
- *
- *
- * @return string
- */
- protected function getControllerFile(): string
- {
- return $this->getControllerName().'.php';
- }
-
- /**
- *
- *
- * @return string
- */
- protected function getControllerName(): string
- {
- return Str::of($this->argument('name'))
- ->whenContains('Controller', function ($str) {
- return $str;
- }, function ($str) {
- return $str->append('Controller');
- })->ucfirst()->toString();
- }
-
- /**
- * get stub content
- *
- * @return string
- */
- protected function getStubContent(): string
- {
- return File::get(dirname(__DIR__).DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'controller.stub');
- }
-}
diff --git a/catch/src/Commands/Create/Event.php b/catch/src/Commands/Create/Event.php
deleted file mode 100644
index 95552e7..0000000
--- a/catch/src/Commands/Create/Event.php
+++ /dev/null
@@ -1,100 +0,0 @@
-argument('module'));
-
- $file = $eventPath.$this->getEventFile();
-
- if (File::exists($file)) {
- $answer = $this->ask($file.' already exists, Did you want replace it?', 'Y');
-
- if (! Str::of($answer)->lower()->exactly('y')) {
- exit;
- }
- }
-
- File::put($file, Str::of($this->getStubContent())->replace([
- '{namespace}', '{event}'
- ], [trim(CatchAdmin::getModuleEventsNamespace($this->argument('module')), '\\'), $this->getEventName()])->toString());
-
- if (File::exists($file)) {
- $this->info($file.' has been created');
- } else {
- $this->error($file.' create failed');
- }
- }
-
- /**
- *
- *
- * @return string
- */
- protected function getEventFile(): string
- {
- return $this->getEventName().'.php';
- }
-
- /**
- *
- *
- * @return string
- */
- protected function getEventName(): string
- {
- return Str::of($this->argument('name'))
- ->whenContains('Event', function ($str) {
- return $str;
- }, function ($str) {
- return $str->append('Event');
- })->ucfirst()->toString();
- }
-
- /**
- * get stub content
- *
- * @return string
- */
- protected function getStubContent(): string
- {
- return File::get(dirname(__DIR__).DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'event.stub');
- }
-}
diff --git a/catch/src/Commands/Create/Listener.php b/catch/src/Commands/Create/Listener.php
deleted file mode 100644
index 165852a..0000000
--- a/catch/src/Commands/Create/Listener.php
+++ /dev/null
@@ -1,103 +0,0 @@
-argument('module'));
-
- $file = $eventPath.$this->getListenerFile();
-
- if (File::exists($file)) {
- $answer = $this->ask($file.' already exists, Did you want replace it?', 'Y');
-
- if (! Str::of($answer)->lower()->exactly('y')) {
- exit;
- }
- }
-
- File::put($file, Str::of($this->getStubContent())->replace([
- '{namespace}', '{listener}'
- ], [
- trim(CatchAdmin::getModuleListenersNamespace($this->argument('module')), '\\'),
-
- $this->getListenerName()])->toString());
-
- if (File::exists($file)) {
- $this->info($file.' has been created');
- } else {
- $this->error($file.' create failed');
- }
- }
-
- /**
- *
- *
- * @return string
- */
- protected function getListenerFile(): string
- {
- return $this->getListenerName().'.php';
- }
-
- /**
- *
- *
- * @return string
- */
- protected function getListenerName(): string
- {
- return Str::of($this->argument('name'))
- ->whenContains('Listener', function ($str) {
- return $str;
- }, function ($str) {
- return $str->append('Listener');
- })->ucfirst()->toString();
- }
-
- /**
- * get stub content
- *
- * @return string
- */
- protected function getStubContent(): string
- {
- return File::get(dirname(__DIR__).DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'listener.stub');
- }
-}
diff --git a/catch/src/Commands/Create/Model.php b/catch/src/Commands/Create/Model.php
deleted file mode 100644
index 0dce160..0000000
--- a/catch/src/Commands/Create/Model.php
+++ /dev/null
@@ -1,174 +0,0 @@
-getTableName())) {
- $this->error('Schema ['.$this->getTableName().'] not found');
- exit;
- }
-
- $modelPath = CatchAdmin::getModuleModelPath($this->argument('module'));
-
- $file = $modelPath.$this->getModelFile();
-
- if (File::exists($file)) {
- $answer = $this->ask($file.' already exists, Did you want replace it?', 'Y');
-
- if (! Str::of($answer)->lower()->exactly('y')) {
- exit;
- }
- }
-
- File::put($file, $this->getModelContent());
-
- if (File::exists($file)) {
- $this->info($file.' has been created');
- } else {
- $this->error($file.' create failed');
- }
- }
-
- /**
- *
- *
- * @return string
- */
- protected function getModelFile(): string
- {
- return $this->getModelName().'.php';
- }
-
- /**
- *
- *
- * @return string
- */
- protected function getModelName(): string
- {
- return Str::of($this->argument('model'))->ucfirst()->toString();
- }
-
- /**
- * get stub content
- *
- * @return string
- */
- protected function getStubContent(): string
- {
- return File::get(dirname(__DIR__).DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'model.stub');
- }
-
-
- /**
- * get model content
- *
- * @return string
- */
- protected function getModelContent(): string
- {
- return Str::of($this->getStubContent())
-
- ->replace(
- [
- '{namespace}', '{model}', '{table}', '{fillable}'
- ],
- [
-
- $this->getModelNamespace(), $this->getModelName(),
-
- $this->getTableName(), $this->getFillable()
- ]
- )->toString();
- }
-
- /**
- * get namespace
- *
- * @return string
- */
- protected function getModelNamespace(): string
- {
- return trim(CatchAdmin::getModuleModelNamespace($this->argument('module')), '\\');
- }
-
- /**
- * get table name
- *
- * @return string
- */
- protected function getTableName(): string
- {
- return $this->option('t') ? $this->option('t') :
- Str::of($this->argument('model'))
- ->snake()->lcfirst()->toString();
- }
-
- /**
- *
- *
- * @return string
- */
- protected function getFillable(): string
- {
- $fillable = Str::of('');
-
-
- foreach (getTableColumns($this->getTableName()) as $column) {
- $fillable = $fillable->append("'{$column}', ");
- }
-
-
- return $fillable->trim(',')->toString();
- }
-}
diff --git a/catch/src/Commands/InstallCommand.php b/catch/src/Commands/InstallCommand.php
deleted file mode 100644
index 4f278b3..0000000
--- a/catch/src/Commands/InstallCommand.php
+++ /dev/null
@@ -1,316 +0,0 @@
-detectionEnvironment();
-
- $this->copyEnvFile();
-
- $this->askForCreatingDatabase();
-
- $this->publishConfig();
-
- $this->installed();
- } catch (\Throwable $e) {
- File::delete(app()->environmentFilePath());
-
- $this->error($e->getMessage());
- }
- }
-
- /**
- * 环境检测
- *
- * @return void
- */
- protected function detectionEnvironment(): void
- {
- $this->checkPHPVersion();
-
- $this->checkExtensions();
- }
-
-
- /**
- * check needed php extensions
- */
- private function checkExtensions()
- {
- /* @var Collection $loadedExtensions */
- $loadedExtensions = Collection::make(get_loaded_extensions())->map(function ($item) {
- return strtolower($item);
- });
-
- Collection::make($this->defaultExtensions)
- ->each(function ($extension) use ($loadedExtensions, &$continue) {
- $extension = strtolower($extension);
-
- if (! $loadedExtensions->contains($extension)) {
- $this->error("$extension extension 未安装");
- }
- });
- }
-
- /**
- * check php version
- */
- private function checkPHPVersion()
- {
- if (version_compare(PHP_VERSION, '8.1.0', '<')) {
- // $this->error('php version should >= 8.1');
- }
- }
-
-
- /**
- * create database
- *
- * @param string $databaseName
- * @return void
- * @throws BindingResolutionException
- */
- private function createDatabase(string $databaseName): void
- {
- $databaseConfig = config('database.connections.'.DB::getDefaultConnection());
-
- $databaseConfig['database'] = null;
-
- app(ConnectionFactory::class)->make($databaseConfig)->select(sprintf("create database if not exists $databaseName default charset %s collate %s", 'utf8mb4', 'utf8mb4_general_ci'));
- }
-
- /**
- * copy .env
- *
- * @return void
- */
- protected function copyEnvFile(): void
- {
- if (! File::exists(app()->environmentFilePath())) {
- File::copy(app()->environmentFilePath().'.example', app()->environmentFilePath());
- }
-
- if (! File::exists(app()->environmentFilePath())) {
- $this->error('【.env】创建失败, 请重新尝试或者手动创建!');
- }
-
- File::put(app()->environmentFile(), implode("\n", explode("\n", $this->getEnvFileContent())));
- }
-
- /**
- * get env file content
- *
- * @return string
- */
- protected function getEnvFileContent(): string
- {
- return File::get(app()->environmentFile());
- }
-
- /**
- * publish config
- *
- * @return void
- */
- protected function publishConfig(): void
- {
- // can't use Artisan::call, it will block the process, no reason found, just block!!!
- exec(Application::formatCommandString('key:generate'));
-
- exec(Application::formatCommandString('vendor:publish --tag=catch-config'));
-
- exec(Application::formatCommandString('vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"'));
-
- exec(Application::formatCommandString('jwt:secret'));
- }
-
- /**
- * create database
- */
- protected function askForCreatingDatabase()
- {
- $appUrl = $this->askFor('请配置应用的 URL');
-
- if ($appUrl && ! Str::contains($appUrl, 'http://') && ! Str::contains($appUrl, 'https://')) {
- $appUrl = 'http://'.$appUrl;
- }
-
- $databaseName = $this->askFor('请输入数据库名称');
-
- $prefix = $this->askFor('请输入数据库表前缀', '');
-
- $dbHost = $this->askFor('请输入数据库主机地址', '127.0.0.1');
-
- $dbPort = $this->askFor('请输入数据的端口号', 3306);
-
- $dbUsername = $this->askFor('请输入数据的用户名', 'root');
-
- $dbPassword = $this->askFor('请输入数据库密码');
-
- if (! $dbPassword) {
- $dbPassword = $this->askFor('确认数据库密码为空吗?');
- }
-
- // set env
- $env = explode("\n", $this->getEnvFileContent());
-
- foreach ($env as &$value) {
- foreach ([
- 'APP_URL' => $appUrl,
- 'DB_HOST' => $dbHost,
- 'DB_PORT' => $dbPort,
- 'DB_DATABASE' => $databaseName,
- 'DB_USERNAME' => $dbUsername,
- 'DB_PASSWORD' => $dbPassword,
- 'DB_PREFIX' => $prefix
- ] as $key => $newValue) {
- if (Str::contains($value, $key)) {
- $value = $this->resetEnvValue($value, $newValue);
- }
- }
- }
-
- // add vite config
- $env[] = 'VITE_BASE_URL=${APP_URL}/api/';
-
- File::put(app()->environmentFile(), implode("\n", $env));
-
- app()->bootstrapWith([
- LoadEnvironmentVariables::class,
- LoadConfiguration::class
- ]);
-
- $this->info("正在创建数据库[$databaseName]...");
-
- $this->createDatabase($databaseName);
-
- $this->info("创建数据库[$databaseName] 成功");
- }
-
- /**
- * @param $originValue
- * @param $newValue
- * @return string
- */
- protected function resetEnvValue($originValue, $newValue): string
- {
- if (Str::contains($originValue, '=')) {
- $originValue = explode('=', $originValue);
-
- $originValue[1] = $newValue;
-
- return implode('=', $originValue);
- }
-
- return $originValue;
- }
-
- /**
- * add prs4 autoload
- */
- protected function addPsr4Autoload()
- {
- $composerFile = base_path().DIRECTORY_SEPARATOR.'composer.json';
-
- $composerJson = json_decode(File::get(base_path().DIRECTORY_SEPARATOR.'composer.json'), true);
-
- $composerJson['autoload']['psr-4'][CatchAdmin::getModuleRootNamespace()] = str_replace('\\', '/', config('catch.module.root'));
-
- File::put($composerFile, json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
-
- $this->info('composer dump autoload..., 请耐心等待');
-
- app(Composer::class)->dumpAutoloads();
- }
-
- /**
- * admin installed
- */
- public function installed()
- {
- $this->addPsr4Autoload();
-
- $this->info('🎉 CatchAdmin 已安装, 欢迎!');
-
- $this->output->info(sprintf('
- /------------------------ welcome ----------------------------\
-| __ __ ___ __ _ |
-| _________ _/ /______/ /_ / | ____/ /___ ___ (_)___ |
-| / ___/ __ `/ __/ ___/ __ \ / /| |/ __ / __ `__ \/ / __ \ |
-| / /__/ /_/ / /_/ /__/ / / / / ___ / /_/ / / / / / / / / / / |
-| \___/\__,_/\__/\___/_/ /_/ /_/ |_\__,_/_/ /_/ /_/_/_/ /_/ |
-| |
- \ __ __ __ __ _ __ _ __ enjoy it ! _ __ __ __ __ __ __ ___ _ @
- 版本: %s
- 初始账号: catch@admin.com
- 初始密码: catchadmin', CatchAdmin::VERSION));
-
- $this->support();
- }
-
- /**
- * support
- *
- * @return void
- */
- protected function support(): void
- {
- $answer = $this->askFor('支持我们! 感谢在 Github 上 star 该项目', 'yes', true);
-
- if (in_array(strtolower($answer), ['yes', 'y'])) {
- if (PHP_OS_FAMILY == 'Darwin') {
- exec('open https://github.com/JaguarJack/catch-admin');
- }
- if (PHP_OS_FAMILY == 'Windows') {
- exec('start https://github.com/JaguarJack/catch-admin');
- }
- if (PHP_OS_FAMILY == 'Linux') {
- exec('xdg-open https://github.com/JaguarJack/catch-admin');
- }
- }
-
- $this->info('支 持: https://github.com/jaguarjack/catchadmin');
- $this->info('文 档: https://catchadmin.com/docs/3.0/intro');
- $this->info('官 网: https://catchadmin.com');
- }
-}
diff --git a/catch/src/Commands/Migrate/MigrateFresh.php b/catch/src/Commands/Migrate/MigrateFresh.php
deleted file mode 100644
index 957e01d..0000000
--- a/catch/src/Commands/Migrate/MigrateFresh.php
+++ /dev/null
@@ -1,55 +0,0 @@
-argument('module');
-
- if (! File::isDirectory(CatchAdmin::getModuleMigrationPath($module))) {
- Artisan::call('migration:fresh', [
- '--path' => CatchAdmin::getModuleRelativePath(CatchAdmin::getModuleMigrationPath($module)),
-
- '--force' => $this->option('force')
- ]);
- } else {
- $this->error('No migration files in module');
- }
- }
-}
diff --git a/catch/src/Commands/Migrate/MigrateMake.php b/catch/src/Commands/Migrate/MigrateMake.php
deleted file mode 100644
index f406a47..0000000
--- a/catch/src/Commands/Migrate/MigrateMake.php
+++ /dev/null
@@ -1,91 +0,0 @@
-argument('module'));
-
- $file = $migrationPath.$this->getMigrationFile();
-
- File::put($file, Str::of($this->getStubContent())->replace(
- '{table}',
- $this->getTable()
- )->toString());
-
-
- if (File::exists($file)) {
- $this->info($file.' has been created');
- } else {
- $this->error($file.' create failed');
- }
- }
-
- /**
- *
- *
- * @return string
- */
- protected function getMigrationFile(): string
- {
- return date('Y_m_d_His').'_create_'.$this->getTable().'.php';
- }
-
- /**
- *
- *
- * @return string
- */
- protected function getTable(): string
- {
- return Str::of($this->argument('table'))->ucfirst()->snake()->lower()->toString();
- }
-
- /**
- * get stub content
- *
- * @return string
- */
- protected function getStubContent(): string
- {
- return File::get(dirname(__DIR__).DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'migration.stub');
- }
-}
diff --git a/catch/src/Commands/Migrate/MigrateRun.php b/catch/src/Commands/Migrate/MigrateRun.php
deleted file mode 100644
index 4511ed0..0000000
--- a/catch/src/Commands/Migrate/MigrateRun.php
+++ /dev/null
@@ -1,74 +0,0 @@
-argument('module');
-
- if (File::isDirectory(CatchAdmin::getModuleMigrationPath($module))) {
- foreach (File::files(CatchAdmin::getModuleMigrationPath($module)) as $file) {
- $path = Str::of(CatchAdmin::getModuleRelativePath(CatchAdmin::getModuleMigrationPath($module)))
-
- ->remove('.')->append($file->getFilename());
-
- Artisan::call('migrate', [
- '--path' => $path,
-
- '--force' => $this->option('force')
- ]);
- }
-
- $this->info("Module [$module] migrate success");
- } else {
- $this->error('No migration files in module');
- }
- }
-}
diff --git a/catch/src/Commands/Migrate/MigrationRollback.php b/catch/src/Commands/Migrate/MigrationRollback.php
deleted file mode 100644
index 55d4278..0000000
--- a/catch/src/Commands/Migrate/MigrationRollback.php
+++ /dev/null
@@ -1,65 +0,0 @@
-argument('module');
-
- if (! File::isDirectory(CatchAdmin::getModuleMigrationPath($module))) {
- Artisan::call('migration:rollback', [
- '--path' => CatchAdmin::getModuleRelativePath(CatchAdmin::getModuleMigrationPath($module)),
-
- '--force' => $this->option('force')
- ]);
- } else {
- $this->error('No migration files in module');
- }
- }
-}
diff --git a/catch/src/Commands/Migrate/SeedRun.php b/catch/src/Commands/Migrate/SeedRun.php
deleted file mode 100644
index 34ef8c2..0000000
--- a/catch/src/Commands/Migrate/SeedRun.php
+++ /dev/null
@@ -1,88 +0,0 @@
-loadModuleSeeders();
-
- if ($class = $this->option('class')) {
- (new $class())->run();
- } else {
- foreach ($classes as $class) {
- $class = new $class();
- if (method_exists($class, 'run')) {
- $class->run();
- }
- }
- }
-
- $this->info('Seed run successfully');
- }
-
-
- /**
- *
- * @time 2021年07月31日
- * @return array
- */
- protected function loadModuleSeeders(): array
- {
- $files = File::allFiles(CatchAdmin::getModuleSeederPath($this->argument('module')));
-
- $fileNames = [];
-
- foreach ($files as $file) {
- require_once $file->getRealPath();
-
- $fileNames[] = pathinfo($file->getBasename(), PATHINFO_FILENAME);
- }
-
- return $fileNames;
- }
-}
diff --git a/catch/src/Commands/Migrate/SeederMake.php b/catch/src/Commands/Migrate/SeederMake.php
deleted file mode 100644
index 8aa1557..0000000
--- a/catch/src/Commands/Migrate/SeederMake.php
+++ /dev/null
@@ -1,88 +0,0 @@
-argument('module'));
-
- $file = $seederPath.$this->getSeederName().'.php';
-
- if (File::exists($file)) {
- $answer = $this->ask($file.' already exists, Did you want replace it?', 'Y');
-
- if (! Str::of($answer)->lower()->exactly('y')) {
- exit;
- }
- }
-
- File::put($file, $this->getSeederContent());
-
- if (File::exists($file)) {
- $this->info($file.' has been created');
- } else {
- $this->error($file.' create failed');
- }
- }
-
- /**
- * seeder content
- *
- * @return string
- * @throws \Exception
- */
- protected function getSeederContent(): string
- {
- return File::get(dirname(__DIR__).DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'seeder.stub');
- }
-
- /**
- * seeder name
- *
- * @return string
- */
- protected function getSeederName(): string
- {
- return Str::of($this->argument('name'))->ucfirst()->toString();
- }
-}
diff --git a/catch/src/Commands/stubs/controller.stub b/catch/src/Commands/stubs/controller.stub
deleted file mode 100644
index ddaac06..0000000
--- a/catch/src/Commands/stubs/controller.stub
+++ /dev/null
@@ -1,35 +0,0 @@
-name();
- }
-
-
- /**
- * get value
- *
- * @return int
- */
- public function value(): int
- {
- return match ($this) {
- Code::SUCCESS => 10000,
- Code::LOST_LOGIN => 10001,
- Code::VALIDATE_FAILED => 10002,
- Code::PERMISSION_FORBIDDEN => 10003,
- Code::LOGIN_FAILED => 10004,
- Code::FAILED => 10005,
- Code::LOGIN_EXPIRED => 10006,
- Code::LOGIN_BLACKLIST => 10007,
- Code::USER_FORBIDDEN => 10008,
- Code::WECHAT_RESPONSE_ERROR => 40000,
- };
- }
-
- /**
- * name
- *
- * @return string
- */
- public function name(): string
- {
- return match ($this) {
- self::SUCCESS => '操作成功',
- self::LOST_LOGIN => '登陆失效',
- self::VALIDATE_FAILED => '验证失败',
- self::PERMISSION_FORBIDDEN => '权限禁止',
- self::LOGIN_FAILED => '登陆失败',
- self::FAILED => '操作失败',
- self::LOGIN_EXPIRED => '登陆过期',
- self::LOGIN_BLACKLIST => '已被加入黑名单',
- self::USER_FORBIDDEN => '账户被禁用',
- self::WECHAT_RESPONSE_ERROR => '微信响应错误'
- };
- }
-}
diff --git a/catch/src/Enums/Enum.php b/catch/src/Enums/Enum.php
deleted file mode 100644
index e344303..0000000
--- a/catch/src/Enums/Enum.php
+++ /dev/null
@@ -1,10 +0,0 @@
- '启用',
-
- Status::Disable => '禁用'
- };
- }
-
- /**
- * get value
- *
- * @return int
- */
- public function value(): int
- {
- return match ($this) {
- Status::Enable => 1,
-
- Status::Disable => 2,
- };
- }
-}
diff --git a/catch/src/Events/Module/Created.php b/catch/src/Events/Module/Created.php
deleted file mode 100644
index 6d5ac32..0000000
--- a/catch/src/Events/Module/Created.php
+++ /dev/null
@@ -1,21 +0,0 @@
-user = $user;
- }
-}
diff --git a/catch/src/Exceptions/CatchException.php b/catch/src/Exceptions/CatchException.php
deleted file mode 100644
index 9e3020c..0000000
--- a/catch/src/Exceptions/CatchException.php
+++ /dev/null
@@ -1,65 +0,0 @@
-value();
- }
-
- if ($this->code instanceof Enum && ! $code) {
- $code = $this->code->value();
- }
-
- parent::__construct($this->statusCode(), $message ?: $this->message, null, [], $code);
- }
-
- /**
- * status code
- *
- * @return int
- */
- public function statusCode(): int
- {
- return 500;
- }
-
- /**
- * render
- *
- * @return array
- */
- public function render(): array
- {
- return [
- 'code' => $this->code,
-
- 'message' => $this->message
- ];
- }
-}
diff --git a/catch/src/Exceptions/FailedException.php b/catch/src/Exceptions/FailedException.php
deleted file mode 100644
index 715d614..0000000
--- a/catch/src/Exceptions/FailedException.php
+++ /dev/null
@@ -1,22 +0,0 @@
-dontReport = config('catch.exception.dont_report');
-
- $this->dontFlash = config('catch.exception.dont_flash');
- }
- }
-}
diff --git a/catch/src/Exceptions/UnMatchedTokenException.php b/catch/src/Exceptions/UnMatchedTokenException.php
deleted file mode 100644
index a034044..0000000
--- a/catch/src/Exceptions/UnMatchedTokenException.php
+++ /dev/null
@@ -1,22 +0,0 @@
-response;
-
- if ($response instanceof JsonResponse) {
- $exception = $response->exception;
-
- if ($response->getStatusCode() == SymfonyResponse::HTTP_OK && ! $exception) {
- $response->setData($this->formatData($response->getData()));
- }
- }
- }
-
- /**
- * @param mixed $data
- * @return array
- */
- protected function formatData(mixed $data): array
- {
- $responseData = [
- 'code' => Code::SUCCESS->value(),
- 'message' => Code::SUCCESS->message(),
- ];
-
- if (is_object($data) && property_exists($data, 'per_page')
- && property_exists($data, 'total')
- && property_exists($data, 'current_page')) {
- $responseData['data'] = $data->data;
- $responseData['total'] = $data->total;
- $responseData['limit'] = $data->per_page;
- $responseData['page'] = $data->current_page;
-
- return $responseData;
- }
-
- $responseData['data'] = $data;
-
- return $responseData;
- }
-}
diff --git a/catch/src/Middleware/AuthMiddleware.php b/catch/src/Middleware/AuthMiddleware.php
deleted file mode 100644
index f35b0c9..0000000
--- a/catch/src/Middleware/AuthMiddleware.php
+++ /dev/null
@@ -1,43 +0,0 @@
-user()) {
- throw new AuthenticationException();
- }
-
- Event::dispatch(new UserEvent($user));
-
- return $next($request);
- } catch (Exception|Throwable $e) {
- if ($e instanceof TokenExpiredException) {
- throw new FailedException(Code::LOGIN_EXPIRED->message(), Code::LOGIN_EXPIRED);
- }
-
- if ($e instanceof TokenBlacklistedException) {
- throw new FailedException(Code::LOGIN_BLACKLIST->message(), Code::LOGIN_BLACKLIST);
- }
-
- throw new FailedException(Code::LOST_LOGIN->message().":{$e->getMessage()}", Code::LOST_LOGIN);
- }
- }
-}
diff --git a/catch/src/Middleware/JsonResponseMiddleware.php b/catch/src/Middleware/JsonResponseMiddleware.php
deleted file mode 100644
index 95cfe23..0000000
--- a/catch/src/Middleware/JsonResponseMiddleware.php
+++ /dev/null
@@ -1,21 +0,0 @@
-getContent());
- }
-
- return $response;
- }
-}
diff --git a/catch/src/Providers/CatchAdminServiceProvider.php b/catch/src/Providers/CatchAdminServiceProvider.php
deleted file mode 100644
index ef29c6e..0000000
--- a/catch/src/Providers/CatchAdminServiceProvider.php
+++ /dev/null
@@ -1,229 +0,0 @@
-bootDefaultModuleProviders();
- $this->bootModuleProviders();
-
- $this->registerEvents();
-
- $this->listenDBLog();
-
- $this->mergeAuthConfig();
-
- // $this->registerExceptionHandler();
-
- MacrosRegister::boot();
- }
-
- /**
- * register
- *
- * @return void
- * @throws ReflectionException
- */
- public function register(): void
- {
- $this->registerCommands();
-
- $this->registerModuleRepository();
-
- $this->publishConfig();
-
- $this->publishModuleMigration();
- }
-
-
- /**
- * register commands
- *
- * @return void
- * @throws ReflectionException
- */
- protected function registerCommands(): void
- {
- loadCommands(dirname(__DIR__).DIRECTORY_SEPARATOR.'Commands', 'Catch\\');
- }
-
- /**
- * register exception handler
- *
- * @return void
- */
- protected function registerExceptionHandler(): void
- {
- $this->app->singleton(
- ExceptionHandler::class,
- Handler::class
- );
- }
-
- /**
- * bind module repository
- *
- * @return void
- */
- protected function registerModuleRepository(): void
- {
- // register module manager
- $this->app->singleton(ModuleManager::class, function () {
- return new ModuleManager(fn () => Container::getInstance());
- });
-
- // register module repository
- $this->app->singleton(ModuleRepositoryInterface::class, function () {
- return $this->app->make(ModuleManager::class)->driver();
- });
-
- $this->app->alias(ModuleRepositoryInterface::class, 'module');
- }
-
- /**
- * register events
- *
- * @return void
- */
- protected function registerEvents(): void
- {
- Event::listen(RequestHandled::class, config('catch.response.request_handled_listener'));
- }
-
- /**
- * publish config
- *
- * @return void
- */
- protected function publishConfig(): void
- {
- if ($this->app->runningInConsole()) {
- $from = dirname(__DIR__, 2).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'catch.php';
-
- $to = config_path('catch.php');
-
- $this->publishes([$from => $to], 'catch-config');
- }
- }
-
-
- /**
- * publish module migration
- *
- * @return void
- */
- protected function publishModuleMigration(): void
- {
- if ($this->app->runningInConsole()) {
- $form = dirname(__DIR__, 2).DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR.'2022_11_14_034127_module.php';
-
- $to = database_path('migrations').DIRECTORY_SEPARATOR.'2022_11_14_034127_module.php';
-
- $this->publishes([$form => $to], 'catch-module');
- }
- }
-
- /**
- *
- * @return void
- * @throws NotFoundExceptionInterface
- * @throws ContainerExceptionInterface
- */
- protected function bootDefaultModuleProviders(): void
- {
- foreach ($this->app['config']->get('catch.module.default') as $module) {
- $provider = CatchAdmin::getModuleServiceProvider($module);
- if (class_exists($provider)) {
- $this->app->register($provider);
- }
- }
- }
-
- /**
- * boot module
- *
- * @throws BindingResolutionException
- */
- protected function bootModuleProviders()
- {
- foreach ($this->app->make(ModuleRepositoryInterface::class)->getEnabled() as $module) {
- if (class_exists($module['provider'])) {
- $this->app->register($module['provider']);
- }
- }
- }
-
- /**
- * listen db log
- *
- * @throws ContainerExceptionInterface
- * @throws NotFoundExceptionInterface
- * @return void
- */
- protected function listenDBLog(): void
- {
- if ($this->app['config']->get('catch.listen_db_log')) {
- Query::listen();
-
- $this->app->terminating(function () {
- Query::log();
- });
- }
- }
-
- /**
- * merge auth config
- *
- * @throws BindingResolutionException
- * @return void
- */
- protected function mergeAuthConfig(): void
- {
- if (! $this->app->configurationIsCached()) {
- $config = $this->app->make('config');
-
- $config->set('auth', array_merge_recursive(
- $config->get('catch.auth', []),
- $config->get('auth', [])
- ));
- }
- }
-}
diff --git a/catch/src/Providers/CatchModuleServiceProvider.php b/catch/src/Providers/CatchModuleServiceProvider.php
deleted file mode 100644
index f292f23..0000000
--- a/catch/src/Providers/CatchModuleServiceProvider.php
+++ /dev/null
@@ -1,63 +0,0 @@
-registerModuleRoute();
-
- foreach ($this->events as $event => $listener) {
- Event::listen($event, $listener);
- }
- }
-
- /**
- * load module router
- *
- * @return void
- * @throws NotFoundExceptionInterface
- * @throws ContainerExceptionInterface
- */
- protected function registerModuleRoute(): void
- {
- $route = $this->app['config']->get('catch.route');
-
- Route::prefix($route['prefix'])
- ->middleware($route['middlewares'])
- ->group($this->routePath());
- }
-
- /**
- * route path
- *
- * @return string|array
- */
- abstract protected function routePath(): string | array;
-}
diff --git a/catch/src/Support/Composer.php b/catch/src/Support/Composer.php
deleted file mode 100644
index 421e78e..0000000
--- a/catch/src/Support/Composer.php
+++ /dev/null
@@ -1,108 +0,0 @@
-checkPHPVersion();
-
- $command = ['require', $package];
-
- return $this->runCommand($command);
- }
-
- /**
- * require dev-package
- *
- * @param string $package
- * @return string
- * @throws PhpVersionNotSupportedException
- */
- public function requireDev(string $package): string
- {
- $this->checkPHPVersion();
-
- $command = ['require', '--dev', $package];
-
- return $this->runCommand($command);
- }
-
-
- /**
- * remove
- *
- * @param string $package
- */
- public function remove(string $package)
- {
- $this->runCommand([
- 'remove', $package
- ]);
- }
-
- /**
- *
- * @param array $command
- * @return string
- */
- protected function runCommand(array $command): string
- {
- $command = array_merge($this->findComposer(), $command);
-
- if ($this->ignorePlatformReqs) {
- $command[] = '--ignore-platform-reqs';
- }
-
- $process = $this->getProcess($command);
-
- $process->run();
-
- return $process->getOutput();
- }
-
- /**
- *
- * @throws PhpVersionNotSupportedException
- * @return void
- */
- protected function checkPHPVersion(): void
- {
- $composerJson = json_decode(File::get(base_path().DIRECTORY_SEPARATOR.'composer.json'), true);
-
- $phpVersion = PHP_VERSION;
-
- $needPHPVersion = Str::of($composerJson['require']['php'])->remove('^');
-
- if (version_compare($phpVersion, $needPHPVersion, '<') && ! $this->ignorePlatformReqs) {
- throw new PhpVersionNotSupportedException("PHP $phpVersion 版本太低, 需要 PHP {$needPHPVersion}!如果想忽略版本要求, s可使用 {ignorePlatFormReqs} 方法然后安装");
- }
- }
-
-
- /**
- *
- * @return $this
- */
- public function ignorePlatFormReqs(): static
- {
- $this->ignorePlatformReqs = true;
-
- return $this;
- }
-}
diff --git a/catch/src/Support/DB/Query.php b/catch/src/Support/DB/Query.php
deleted file mode 100644
index be1362b..0000000
--- a/catch/src/Support/DB/Query.php
+++ /dev/null
@@ -1,55 +0,0 @@
-sql.' | %s ms'.PHP_EOL, date('Y-m-d H:i'), $query->time)
- );
-
- static::$log .= vsprintf($sql, $query->bindings);
- });
- }
-
-
- /**
- * @return void
- */
- public static function log(): void
- {
- if (static::$log) {
- $sqlLogPath = storage_path('logs'.DIRECTORY_SEPARATOR.'query'.DIRECTORY_SEPARATOR);
-
- if (! File::isDirectory($sqlLogPath)) {
- File::makeDirectory($sqlLogPath, 0777, true);
- }
-
- $logFile = $sqlLogPath.date('Ymd').'.log';
-
- if (! File::exists($logFile)) {
- File::put($logFile, '', true);
- }
-
- file_put_contents($logFile, static::$log.PHP_EOL, LOCK_EX | FILE_APPEND);
-
- static::$log = null;
- }
- }
-}
diff --git a/catch/src/Support/DB/SoftDelete.php b/catch/src/Support/DB/SoftDelete.php
deleted file mode 100644
index 585285f..0000000
--- a/catch/src/Support/DB/SoftDelete.php
+++ /dev/null
@@ -1,19 +0,0 @@
-where($model->getQualifiedDeletedAtColumn(), '=', 0);
- }
-}
diff --git a/catch/src/Support/Macros/Blueprint.php b/catch/src/Support/Macros/Blueprint.php
deleted file mode 100644
index 7bd0ac7..0000000
--- a/catch/src/Support/Macros/Blueprint.php
+++ /dev/null
@@ -1,140 +0,0 @@
-createdAt();
-
- $bluePrint->updatedAt();
-
- $bluePrint->deletedAt();
-
- $bluePrint->status();
-
- $bluePrint->creatorId();
-
- $bluePrint->unixTimestamp();
-
- $bluePrint->parentId();
-
- $bluePrint->sort();
- }
-
- /**
- * created unix timestamp
- *
- * @return void
- */
- public function createdAt(): void
- {
- LaravelBlueprint::macro(__FUNCTION__, function () {
- $this->unsignedInteger('created_at')->default(0)->comment('created time');
- });
- }
-
- /**
- * update unix timestamp
- *
- * @return void
- */
- public function updatedAt(): void
- {
- LaravelBlueprint::macro(__FUNCTION__, function () {
- $this->unsignedInteger('updated_at')->default(0)->comment('updated time');
- });
- }
-
- /**
- * soft delete
- *
- * @return void
- */
- public function deletedAt(): void
- {
- LaravelBlueprint::macro(__FUNCTION__, function () {
- $this->unsignedInteger('deleted_at')->default(0)->comment('delete time');
- });
- }
-
-
- /**
- * unix timestamp
- *
- * @param bool $softDeleted
- * @return void
- */
- public function unixTimestamp(bool $softDeleted = true): void
- {
- LaravelBlueprint::macro(__FUNCTION__, function () use ($softDeleted) {
- $this->createdAt();
- $this->updatedAt();
-
- if ($softDeleted) {
- $this->deletedAt();
- }
- });
- }
-
- /**
- * creator id
- *
- * @return void
- */
- public function creatorId(): void
- {
- LaravelBlueprint::macro(__FUNCTION__, function () {
- $this->unsignedInteger('creator_id')->default(0)->comment('creator id');
- });
- }
-
-
- /**
- * parent ID
- *
- * @return void
- */
- public function parentId(): void
- {
- LaravelBlueprint::macro(__FUNCTION__, function () {
- $this->unsignedInteger('parent_id')->default(0)->comment('parent id');
- });
- }
-
-
- /**
- * status
- *
- * @return void
- */
- public function status(): void
- {
- LaravelBlueprint::macro(__FUNCTION__, function ($default = 1) {
- $this->tinyInteger('status')->default($default)->comment('1:normal 2: forbidden');
- });
- }
-
- /**
- * sort
- *
- * @param int $default
- * @return void
- */
- public function sort(int $default = 1): void
- {
- LaravelBlueprint::macro(__FUNCTION__, function () use ($default) {
- $this->integer('sort')->comment('sort')->default($default);
- });
- }
-}
diff --git a/catch/src/Support/Macros/Builder.php b/catch/src/Support/Macros/Builder.php
deleted file mode 100644
index 4706554..0000000
--- a/catch/src/Support/Macros/Builder.php
+++ /dev/null
@@ -1,107 +0,0 @@
-whereLike();
-
- $builder->quickSearch();
-
- $builder->tree();
- }
-
- /**
- * where like
- *
- * @return void
- */
- public function whereLike(): void
- {
- LaravelBuilder::macro(__FUNCTION__, function ($filed, $value) {
- return $this->where($filed, 'like', "%$value%");
- });
- }
-
-
- /**
- * quick search
- *
- * @return void
- */
- public function quickSearch(): void
- {
- LaravelBuilder::macro(__FUNCTION__, function (array $params = []) {
- $params = array_merge(request()->all(), $params);
-
- if (! property_exists($this->model, 'searchable')) {
- return $this;
- }
-
- // filter null & empty string
- $params = array_filter($params, function ($value) {
- return (is_string($value) && strlen($value)) || is_numeric($value);
- });
-
- $wheres = [];
-
- if (! empty($this->model->searchable)) {
- foreach ($this->model->searchable as $field => $op) {
- // 临时变量
- $_field = $field;
- // contains alias
- if (str_contains($field, '.')) {
- [, $_field] = explode('.', $field);
- }
-
- if (isset($params[$_field])) {
- $opString = Str::of($op)->lower();
- if ($opString->exactly('op')) {
- $value = implode(',', $params[$_field]);
- } elseif ($opString->exactly('like')) {
- $value = "%{$params[$_field]}%";
- } elseif ($opString->exactly('rlike')) {
- $value = "{$params[$_field]}%";
- } elseif ($opString->exactly('llike')) {
- $value = "%{$params[$_field]}";
- } else {
- $value = $params[$_field];
- }
- $wheres[] = [$field, $op, $value];
- }
- }
- }
-
- $this->where($wheres);
-
- return $this;
- });
- }
-
- /**
- * where like
- *
- * @time 2021年08月06日
- * @return void
- */
- public function tree(): void
- {
- LaravelBuilder::macro(__FUNCTION__, function (string $id, string $parentId, ...$fields) {
- $fields = array_merge([$id, $parentId], $fields);
-
- return $this->get($fields)->toTree(0, $parentId);
- });
- }
-}
diff --git a/catch/src/Support/Macros/Collection.php b/catch/src/Support/Macros/Collection.php
deleted file mode 100644
index 69ff7b9..0000000
--- a/catch/src/Support/Macros/Collection.php
+++ /dev/null
@@ -1,65 +0,0 @@
-toOptions();
-
- $collection->toTree();
- }
-
- /**
- * collection to tree
- *
- * @return void
- */
- public function toTree(): void
- {
- LaravelCollection::macro(__FUNCTION__, function (int $pid = 0, string $pidField = 'parent_id', string $child = 'children') {
- return Tree::done($this->all(), $pid, $pidField, $child);
- });
- }
-
- /**
- * toOptions
- *
- * @return void
- */
- public function toOptions(): void
- {
- LaravelCollection::macro(__FUNCTION__, function () {
- return $this->transform(function ($item, $key) use (&$options) {
- if ($item instanceof Arrayable) {
- $item = $item->toArray();
- }
-
- if (is_array($item)) {
- $item = array_values($item);
- return [
- 'value' => $item[0],
- 'label' => $item[1]
- ];
- } else {
- return [
- 'value' => $key,
- 'label' => $item
- ];
- }
- })->values();
- });
- }
-}
diff --git a/catch/src/Support/Macros/Register.php b/catch/src/Support/Macros/Register.php
deleted file mode 100644
index 1386c5d..0000000
--- a/catch/src/Support/Macros/Register.php
+++ /dev/null
@@ -1,23 +0,0 @@
-model = $this->createModuleModel();
- }
-
- /**
- * all
- *
- * @param array $search
- * @return Collection
- */
- public function all(array $search): Collection
- {
- return $this->model::query()
- ->when($search['title'] ?? false, function ($query) use ($search) {
- $query->where('title', 'like', '%'.$search['title'].'%');
- })->get();
- }
-
- /**
- * create module json
- *
- * @param array $module
- * @return bool|int
- */
- public function create(array $module): bool|int
- {
- $this->hasSameModule($module);
-
- return $this->model->save([
- 'title' => $module['title'],
- 'path' => $module['path'],
- 'description' => $module['desc'],
- 'keywords' => $module['keywords'],
- 'provider' => sprintf('\\%s%s', CatchAdmin::getModuleNamespace($module['name']), ucfirst($module['name']).'ServiceProvider'),
- ]);
- }
-
- /**
- * module info
- *
- * @param string $name
- * @return Collection
- */
- public function show(string $name): Collection
- {
- return $this->model->where('name', $name)->first();
- }
-
- /**
- * update module json
- *
- * @param string $name
- * @param array $module
- * @return bool|int
- */
- public function update(string $name, array $module): bool|int
- {
- return $this->model->where('name', $name)
-
- ->update([
- 'title' => $module['title'],
- 'name' => $module['path'],
- 'path' => $module['path'],
- 'description' => $module['desc'],
- 'keywords' => $module['keywords'],
- ]);
- }
-
- /**
- * delete module json
- *
- * @param string $name
- * @return bool|int
- */
- public function delete(string $name): bool|int
- {
- return $this->model->where('name', $name)->delete();
- }
-
- /**
- * disable or enable
- *
- * @param $name
- * @return bool|int
- */
- public function disOrEnable($name): bool|int
- {
- $module = $this->show($name);
-
- $module->enable = (int) $module->enable;
-
- return $module->save();
- }
-
- /**
- * get enabled
- *
- * @return Collection
- */
- public function getEnabled(): Collection
- {
- // TODO: Implement getEnabled() method.
- return $this->model->where('enable', Status::Enable->value())->get();
- }
-
- /**
- * enabled
- *
- * @param string $moduleName
- * @return bool
- */
- public function enabled(string $moduleName): bool
- {
- // TODO: Implement enabled() method.
- return $this->getEnabled()->pluck('name')->contains($moduleName);
- }
-
- /**
- *
- * @param array $module
- * @return void
- */
- protected function hasSameModule(array $module): void
- {
- if ($this->model->where('name', $module['name'])->first()) {
- throw new FailedException(sprintf('Module [%s] has been created', $module['name']));
- }
- }
-
- /**
- * create model
- * @return Model
- */
- protected function createModuleModel(): Model
- {
- return new class () extends Model {
- protected $table;
-
- public function __construct(array $attributes = [])
- {
- parent::__construct($attributes);
-
- $this->table = Container::getInstance()->make('config')->get('catch.module.driver.table_name');
- }
- };
- }
-}
diff --git a/catch/src/Support/Module/Driver/FileDriver.php b/catch/src/Support/Module/Driver/FileDriver.php
deleted file mode 100644
index 3e70f26..0000000
--- a/catch/src/Support/Module/Driver/FileDriver.php
+++ /dev/null
@@ -1,215 +0,0 @@
-moduleJson = storage_path('app').DIRECTORY_SEPARATOR.'modules.json';
- }
-
- /**
- * all
- *
- * @param array $search
- * @return Collection
- */
- public function all(array $search = []): Collection
- {
- if (! File::exists($this->moduleJson)) {
- return Collection::make([]);
- }
-
- if (! Str::length(File::get($this->moduleJson))) {
- return Collection::make([]);
- }
-
- $modules = Collection::make(\json_decode(File::get($this->moduleJson), true))->values();
-
- $title = $search['title'] ?? '';
-
- if (! $title) {
- return $modules;
- }
-
- return $modules->filter(function ($module) use ($title) {
- return Str::of($module['title'])->contains($title);
- });
- }
-
- /**
- * create module json
- *
- * @param array $module
- * @return bool
- */
- public function create(array $module): bool
- {
- $modules = $this->all();
-
- $this->hasSameModule($module, $modules);
-
- $module['provider'] = sprintf('\\%s', CatchAdmin::getModuleServiceProvider($module['path']));
- $module['version'] = '1.0.0';
- $module['enable'] = true;
-
- $this->removeDirs($module);
-
- File::put($this->moduleJson, $modules->push($module)->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
-
- return true;
- }
-
- /**
- * module info
- *
- * @param string $name
- * @return Collection
- */
- public function show(string $name): Collection
- {
- foreach ($this->all() as $module) {
- if (Str::of($module['name'])->exactly($name)) {
- return Collection::make($module);
- }
- }
-
- throw new FailedException("Module [$name] not Found");
- }
-
- /**
- * update module json
- *
- * @param string $name
- * @param array $module
- * @return bool
- */
- public function update(string $name, array $module): bool
- {
- File::put($this->moduleJson, $this->all()->map(function ($m) use ($module, $name) {
- if (Str::of($name)->exactly($m['name'])) {
- $m['name'] = $module['name'];
- $m['title'] = $module['title'];
- $m['description'] = $module['description'] ?? '';
- $m['keywords'] = $module['keywords'] ?? '';
- $m['enable'] = $module['enable'];
- }
- $this->removeDirs($m);
- return $m;
- })->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
-
- return true;
- }
-
- /**
- * delete module json
- *
- * @param string $name
- * @return bool
- */
- public function delete(string $name): bool
- {
- File::put($this->moduleJson, $this->all()->filter(function ($module) use ($name) {
- if (! Str::of($name)->exactly($module['name'])) {
- return $module;
- }
- })->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
-
-
- return true;
- }
-
- /**
- * disable or enable
- *
- * @param $name
- * @return bool|int
- */
- public function disOrEnable($name): bool|int
- {
- return File::put($this->moduleJson, $this->all()->map(function ($module) use ($name) {
- if (Str::of($module['name'])->exactly($name)) {
- $module['enable'] = ! $module['enable'];
- }
- return $module;
- })->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
- }
-
- /**
- * get enabled
- *
- * @return Collection
- */
- public function getEnabled(): Collection
- {
- // TODO: Implement getEnabled() method.
- return $this->all()->where('enable', true)->values();
- }
-
- /**
- * enabled
- * @param string $moduleName
- * @return bool
- */
- public function enabled(string $moduleName): bool
- {
- // TODO: Implement enabled() method.
- return $this->getEnabled()->pluck('name')->contains($moduleName);
- }
-
- /**
- *
- * @param array $module
- * @param Collection $modules
- * @return void
- */
- protected function hasSameModule(array $module, Collection $modules): void
- {
- if ($modules->count()) {
- if ($modules->pluck('name')->contains($module['name'])) {
- throw new FailedException(sprintf('Module [%s] has been created', $module['name']));
- }
- }
- }
-
- /**
- * remove dirs
- *
- * @param array $modules
- */
- protected function removeDirs(array &$modules)
- {
- if ($modules['dirs'] ?? false) {
- unset($modules['dirs']);
- }
- }
-}
diff --git a/catch/src/Support/Module/Installer.php b/catch/src/Support/Module/Installer.php
deleted file mode 100644
index c9ecab5..0000000
--- a/catch/src/Support/Module/Installer.php
+++ /dev/null
@@ -1,97 +0,0 @@
-moduleRepository->delete($this->info()['name']);
-
-
- $this->removePackages();
- }
-
- /**
- * invoke
- *
- * @return void
- */
- public function install(): void
- {
- // TODO: Implement __invoke() method.
- $this->moduleRepository->create($this->info());
-
- // migration
-
- // seed
-
- $this->requirePackages();
- }
-
- /**
- * composer installer
- *
- * @return Composer
- */
- protected function composer(): Composer
- {
- return app(Composer::class);
- }
-}
diff --git a/catch/src/Support/Module/ModuleManager.php b/catch/src/Support/Module/ModuleManager.php
deleted file mode 100644
index a50033f..0000000
--- a/catch/src/Support/Module/ModuleManager.php
+++ /dev/null
@@ -1,63 +0,0 @@
-config->get('catch.module.driver.default');
- }
-
- /**
- * create file driver
- *
- * @return FileDriver
- */
- public function createFileDriver(): FileDriver
- {
- return new FileDriver();
- }
-
- /**
- * create database driver
- *
- * @return DatabaseDriver
- */
- public function createDatabaseDriver(): DatabaseDriver
- {
- return new DatabaseDriver();
- }
-}
diff --git a/catch/src/Support/Module/ModuleRepository.php b/catch/src/Support/Module/ModuleRepository.php
deleted file mode 100644
index 20994c4..0000000
--- a/catch/src/Support/Module/ModuleRepository.php
+++ /dev/null
@@ -1,159 +0,0 @@
-moduleRepository = $moduleRepository;
- }
-
- /**
- * all
- *
- * @param array $search
- * @return Collection
- */
- public function all(array $search): Collection
- {
- return $this->moduleRepository->all($search);
- }
-
- /**
- * create module json
- *
- * @param array $module
- * @return bool
- */
- public function create(array $module): bool
- {
- $module['name'] = lcfirst($module['path']);
-
- Event::dispatch(new Creating($module));
-
- $this->moduleRepository->create($module);
-
- Event::dispatch(new Created($module));
-
- return true;
- }
-
- /**
- * module info
- *
- * @param string $name
- * @return Collection
- * @throws Exception
- */
- public function show(string $name): Collection
- {
- try {
- return $this->moduleRepository->show($name);
- } catch (Exception $e) {
- throw new $e();
- }
- }
-
- /**
- * update module json
- *
- * @param string $name
- * @param array $module
- * @return bool
- */
- public function update(string $name, array $module): bool
- {
- $module['name'] = lcfirst($module['path']);
-
- Event::dispatch(new Updating($name, $module));
-
- $this->moduleRepository->update($name, $module);
-
- Event::dispatch(new Updated($name, $module));
-
- return true;
- }
-
- /**
- * delete module json
- *
- * @param string $name
- * @return bool
- * @throws Exception
- */
- public function delete(string $name): bool
- {
- $module = $this->show($name);
-
- $this->moduleRepository->delete($name);
-
- Event::dispatch(new Deleted($module));
-
- return true;
- }
-
- /**
- * disable or enable
- *
- * @param string $name
- * @return bool|int
- */
- public function disOrEnable(string $name): bool|int
- {
- return $this->moduleRepository->disOrEnable($name);
- }
-
- /**
- * get enabled
- *
- * @return Collection
- */
- public function getEnabled(): Collection
- {
- // TODO: Implement getEnabled() method.
- return $this->moduleRepository->getEnabled();
- }
-
- /**
- * enabled
- *
- * @param string $moduleName
- * @return bool
- */
- public function enabled(string $moduleName): bool
- {
- return $this->moduleRepository->enabled($moduleName);
- }
-}
diff --git a/catch/src/Support/Tree.php b/catch/src/Support/Tree.php
deleted file mode 100644
index 74e62e7..0000000
--- a/catch/src/Support/Tree.php
+++ /dev/null
@@ -1,61 +0,0 @@
-archive = $archive ? $archive : new ZipArchive();
-
- $res = $this->archive->open($filePath, ($create ? ZipArchive::CREATE : 0));
- if ($res !== true) {
- throw new Exception("Error: Failed to open $filePath! Error: ".$this->getErrorMessage($res));
- }
- }
-
- /**
- * Add a file to the opened Archive
- *
- * @param $pathToFile
- * @param $pathInArchive
- */
- public function addFile($pathToFile, $pathInArchive): void
- {
- $this->archive->addFile($pathToFile, $pathInArchive);
- }
-
- /**
- * Add an empty directory
- *
- * @param $dirName
- */
- public function addEmptyDir($dirName): void
- {
- $this->archive->addEmptyDir($dirName);
- }
-
- /**
- * Add a file to the opened Archive using its contents
- *
- * @param string $name
- * @param $content
- */
- public function addFromString(string $name, $content): void
- {
- $this->archive->addFromString($name, $content);
- }
-
- /**
- * Remove a file permanently from the Archive
- *
- * @param string $pathInArchive
- */
- public function removeFile(string $pathInArchive): void
- {
- $this->archive->deleteName($pathInArchive);
- }
-
- /**
- * Get the content of a file
- *
- * @param string $pathInArchive
- *
- * @return string
- */
- public function getFileContent(string $pathInArchive): string
- {
- return $this->archive->getFromName($pathInArchive);
- }
-
- /**
- * Get the stream of a file
- *
- * @param string $pathInArchive
- *
- * @return bool
- */
- public function getFileStream(string $pathInArchive): bool
- {
- return $this->archive->getStream($pathInArchive);
- }
-
- /**
- * Will loop over every item in the archive and will execute the callback on them
- * Will provide the filename for every item
- *
- * @param $callback
- */
- public function each($callback): void
- {
- for ($i = 0; $i < $this->archive->numFiles; ++$i) {
- //skip if folder
- $stats = $this->archive->statIndex($i);
- if ($stats['size'] === 0 && $stats['crc'] === 0) {
- continue;
- }
- call_user_func_array($callback, [
- 'file' => $this->archive->getNameIndex($i),
- 'stats' => $this->archive->statIndex($i)
- ]);
- }
- }
-
- /**
- * Checks whether the file is in the archive
- *
- * @param $fileInArchive
- *
- * @return bool
- */
- public function fileExists($fileInArchive): bool
- {
- return $this->archive->locateName($fileInArchive) !== false;
- }
-
- /**
- * Sets the password to be used for decompressing
- * function named usePassword for clarity
- *
- * @param $password
- *
- * @return bool
- */
- public function usePassword($password): bool
- {
- return $this->archive->setPassword($password);
- }
-
- /**
- * Returns the status of the archive as a string
- *
- * @return string
- */
- public function getStatus(): string
- {
- return $this->archive->getStatusString();
- }
-
- /**
- * Closes the archive and saves it
- */
- public function close(): void
- {
- @$this->archive->close();
- }
-
- /**
- * get error message
- *
- * @param $resultCode
- * @return string
- */
- private function getErrorMessage($resultCode): string
- {
- return match ($resultCode) {
- ZipArchive::ER_EXISTS => 'ZipArchive::ER_EXISTS - File already exists.',
- ZipArchive::ER_INCONS => 'ZipArchive::ER_INCONS - Zip archive inconsistent.',
- ZipArchive::ER_MEMORY => 'ZipArchive::ER_MEMORY - Malloc failure.',
- ZipArchive::ER_NOENT => 'ZipArchive::ER_NOENT - No such file.',
- ZipArchive::ER_NOZIP => 'ZipArchive::ER_NOZIP - Not a zip archive.',
- ZipArchive::ER_OPEN => 'ZipArchive::ER_OPEN - Can\'t open file.',
- ZipArchive::ER_READ => 'ZipArchive::ER_READ - Read error.',
- ZipArchive::ER_SEEK => 'ZipArchive::ER_SEEK - Seek error.',
- default => "An unknown error [$resultCode] has occurred.",
- };
- }
-}
diff --git a/catch/src/Support/Zip/Zipper.php b/catch/src/Support/Zip/Zipper.php
deleted file mode 100644
index 53b5bc1..0000000
--- a/catch/src/Support/Zip/Zipper.php
+++ /dev/null
@@ -1,626 +0,0 @@
-file = $fs ? $fs : new Filesystem();
- }
-
- /**
- * Destructor
- */
- public function __destruct()
- {
- if (is_object($this->repository)) {
- $this->repository->close();
- }
- }
-
- /**
- * Create a new zip Archive if the file does not exists
- * opens a zip archive if the file exists
- *
- * @param $pathToFile string The file to open
- * @return $this Zipper instance
- * @throws Exception
- */
- public function make(string $pathToFile): Zipper
- {
- $new = $this->createArchiveFile($pathToFile);
-
- $this->repository = new ZipRepository($pathToFile, $new);
-
- $this->filePath = $pathToFile;
-
- return $this;
- }
-
- /**
- * Create a new zip archive or open an existing one
- *
- * @param $pathToFile
- *
- * @return $this
- * @throws Exception
- *
- */
- public function zip($pathToFile): Zipper
- {
- $this->make($pathToFile);
-
- return $this;
- }
-
- /**
- * Create a new phar file or open one
- *
- * @param $pathToFile
- *
- * @return $this
- * @throws Exception
- *
- */
- public function phar($pathToFile): Zipper
- {
- $this->make($pathToFile, 'phar');
-
- return $this;
- }
-
- /**
- * Create a new rar file or open one
- *
- * @param $pathToFile
- *
- * @return $this
- * @throws Exception
- *
- */
- public function rar($pathToFile): Zipper
- {
- $this->make($pathToFile, 'rar');
-
- return $this;
- }
-
- /**
- * Extracts the opened zip archive to the specified location
- * you can provide an array of files and folders and define if they should be a white list
- * or a black list to extract. By default this method compares file names using "string starts with" logic
- *
- * @param $path string The path to extract to
- * @param array $files An array of files
- * @param int $methodFlags The Method the files should be treated
- *
- * @throws Exception
- */
- public function extractTo(string $path, array $files = [], int $methodFlags = self::BLACKLIST): void
- {
- if (! $this->file->exists($path) && ! $this->file->makeDirectory($path, 0755, true)) {
- throw new RuntimeException('Failed to create folder');
- }
-
- if ($methodFlags & self::EXACT_MATCH) {
- $matchingMethod = function ($haystack) use ($files) {
- return in_array($haystack, $files, true);
- };
- } else {
- $matchingMethod = function ($haystack) use ($files) {
- return Str::startsWith($haystack, $files);
- };
- }
-
- if ($methodFlags & self::WHITELIST) {
- $this->extractFilesInternal($path, $matchingMethod);
- } else {
- // blacklist - extract files that do not match with $matchingMethod
- $this->extractFilesInternal($path, function ($filename) use ($matchingMethod) {
- return ! $matchingMethod($filename);
- });
- }
- }
-
- /**
- * Extracts matching files/folders from the opened zip archive to the specified location.
- *
- * @param string $extractToPath The path to extract to
- * @param string $regex regular expression used to match files. See @link http://php.net/manual/en/reference.pcre.pattern.syntax.php
- *
- * @throws InvalidArgumentException
- * @throws RuntimeException
- */
- public function extractMatchingRegex(string $extractToPath, string $regex): void
- {
- if (empty($regex)) {
- throw new InvalidArgumentException('Missing pass valid regex parameter');
- }
-
- $this->extractFilesInternal($extractToPath, function ($filename) use ($regex) {
- $match = preg_match($regex, $filename);
- if ($match === 1) {
- return true;
- } elseif ($match === false) {
- //invalid pattern for preg_match raises E_WARNING and returns FALSE
- //so if you have custom error_handler set to catch and throw E_WARNINGs you never end up here
- //but if you have not - this will throw exception
- throw new RuntimeException("regular expression match on '$filename' failed with error. Please check if pattern is valid regular expression.");
- }
-
- return false;
- });
- }
-
- /**
- * Gets the content of a single file if available
- *
- * @param $filePath string The full path (including all folders) of the file in the zip
- *
- * @return string returns the content or throws an exception
- * @throws Exception
- *
- */
- public function getFileContent(string $filePath): string
- {
- if ($this->repository->fileExists($filePath) === false) {
- throw new Exception(sprintf('The file "%s" cannot be found', $filePath));
- }
- return $this->repository->getFileContent($filePath);
- }
-
- /**
- * Add one or multiple files to the zip.
- *
- * @param $pathToAdd array|string An array or string of files and folders to add
- * @param mixed|null $fileName
- *
- * @return $this Zipper instance
- */
- public function add(array|string $pathToAdd, mixed $fileName = null): Zipper
- {
- if (is_array($pathToAdd)) {
- foreach ($pathToAdd as $key => $dir) {
- if (! is_int($key)) {
- $this->add($dir, $key);
- } else {
- $this->add($dir);
- }
- }
- } elseif ($this->file->isFile($pathToAdd)) {
- if ($fileName) {
- $this->addFile($pathToAdd, $fileName);
- } else {
- $this->addFile($pathToAdd);
- }
- } else {
- $this->addDir($pathToAdd);
- }
-
- return $this;
- }
-
- /**
- * Add an empty directory
- *
- * @param $dirName
- *
- * @return Zipper
- */
- public function addEmptyDir($dirName): Zipper
- {
- $this->repository->addEmptyDir($dirName);
-
- return $this;
- }
-
- /**
- * Add a file to the zip using its contents
- *
- * @param $filename string The name of the file to create
- * @param $content string The file contents
- *
- * @return $this Zipper instance
- */
- public function addString(string $filename, string $content): Zipper
- {
- $this->addFromString($filename, $content);
-
- return $this;
- }
-
- /**
- * Gets the status of the zip.
- *
- * @return string The status of the internal zip file
- */
- public function getStatus(): string
- {
- return $this->repository->getStatus();
- }
-
- /**
- * Remove a file or array of files and folders from the zip archive
- *
- * @param $fileToRemove array|string The path/array to the files in the zip
- *
- * @return $this Zipper instance
- */
- public function remove(array|string $fileToRemove): Zipper
- {
- if (is_array($fileToRemove)) {
- $self = $this;
- $this->repository->each(function ($file) use ($fileToRemove, $self) {
- if (Str::startsWith($file, $fileToRemove)) {
- $self->getRepository()->removeFile($file);
- }
- });
- } else {
- $this->repository->removeFile($fileToRemove);
- }
-
- return $this;
- }
-
- /**
- * Returns the path of the current zip file if there is one.
- *
- * @return string The path to the file
- */
- public function getFilePath(): string
- {
- return $this->filePath;
- }
-
- /**
- * Sets the password to be used for decompressing
- *
- * @param $password
- *
- * @return bool
- */
- public function usePassword($password): bool
- {
- return $this->repository->usePassword($password);
- }
-
- /**
- * Closes the zip file and frees all handles
- */
- public function close(): void
- {
- if (null !== $this->repository) {
- $this->repository->close();
- }
- $this->filePath = '';
- }
-
- /**
- * Sets the internal folder to the given path.
- * Useful for extracting only a segment of a zip file.
- *
- * @param string $path
- *
- * @return $this
- */
- public function folder(string $path): Zipper
- {
- $this->currentFolder = $path;
-
- return $this;
- }
-
- /**
- * Resets the internal folder to the root of the zip file.
- *
- * @return $this
- */
- public function home(): Zipper
- {
- $this->currentFolder = '';
-
- return $this;
- }
-
- /**
- * Deletes the archive file
- */
- public function delete(): void
- {
- if (null !== $this->repository) {
- $this->repository->close();
- }
-
- $this->file->delete($this->filePath);
- $this->filePath = '';
- }
-
- /**
- * Get the type of the Archive
- *
- * @return string
- */
- public function getArchiveType(): string
- {
- return get_class($this->repository);
- }
-
- /**
- * Get the current internal folder pointer
- *
- * @return string
- */
- public function getCurrentFolderPath(): string
- {
- return $this->currentFolder;
- }
-
- /**
- * Checks if a file is present in the archive
- *
- * @param $fileInArchive
- *
- * @return bool
- */
- public function contains($fileInArchive): bool
- {
- return $this->repository->fileExists($fileInArchive);
- }
-
- /**
- * @return ZipRepository
- */
- public function getRepository(): ZipRepository
- {
- return $this->repository;
- }
-
- /**
- * @return Filesystem
- */
- public function getFileHandler(): Filesystem
- {
- return $this->file;
- }
-
- /**
- * Gets the path to the internal folder
- *
- * @return string
- */
- public function getInternalPath(): string
- {
- return empty($this->currentFolder) ? '' : $this->currentFolder.'/';
- }
-
- /**
- * List all files that are within the archive
- *
- * @param string|null $regexFilter regular expression to filter returned files/folders. See @link http://php.net/manual/en/reference.pcre.pattern.syntax.php
- *
- * @throws RuntimeException
- *
- * @return array
- */
- public function listFiles(string $regexFilter = null): array
- {
- $filesList = [];
- if ($regexFilter) {
- $filter = function ($file) use (&$filesList, $regexFilter) {
- // push/pop an error handler here to to make sure no error/exception thrown if $expected is not a regex
- set_error_handler(function () {
- });
- $match = preg_match($regexFilter, $file);
- restore_error_handler();
-
- if ($match === 1) {
- $filesList[] = $file;
- } elseif ($match === false) {
- throw new RuntimeException("regular expression match on '$file' failed with error. Please check if pattern is valid regular expression.");
- }
- };
- } else {
- $filter = function ($file) use (&$filesList) {
- $filesList[] = $file;
- };
- }
- $this->repository->each($filter);
-
- return $filesList;
- }
-
- private function getCurrentFolderWithTrailingSlash(): string
- {
- if (empty($this->currentFolder)) {
- return '';
- }
-
- $lastChar = mb_substr($this->currentFolder, -1);
- if ($lastChar !== '/' || $lastChar !== '\\') {
- return $this->currentFolder.'/';
- }
-
- return $this->currentFolder;
- }
-
- //---------------------PRIVATE FUNCTIONS-------------
-
- /**
- * @param $pathToZip
- *
- * @return bool
- * @throws Exception
- *
- */
- private function createArchiveFile($pathToZip): bool
- {
- if (! $this->file->exists($pathToZip)) {
- $dirname = dirname($pathToZip);
- if (! $this->file->exists($dirname) && ! $this->file->makeDirectory($dirname, 0755, true)) {
- throw new RuntimeException('Failed to create folder');
- } elseif (! $this->file->isWritable($dirname)) {
- throw new Exception(sprintf('The path "%s" is not writeable', $pathToZip));
- }
-
- return true;
- }
-
- return false;
- }
-
- /**
- * @param $pathToDir
- */
- private function addDir($pathToDir): void
- {
- // First go over the files in this directory and add them to the repository.
- foreach ($this->file->files($pathToDir) as $file) {
- $this->addFile($pathToDir.'/'.basename($file));
- }
-
- // Now let's visit the subdirectories and add them, too.
- foreach ($this->file->directories($pathToDir) as $dir) {
- $old_folder = $this->currentFolder;
- $this->currentFolder = empty($this->currentFolder) ? basename($dir) : $this->currentFolder.'/'.basename($dir);
- $this->addDir($pathToDir.'/'.basename($dir));
- $this->currentFolder = $old_folder;
- }
- }
-
- /**
- * Add the file to the zip
- *
- * @param string $pathToAdd
- * @param string|null $fileName
- */
- private function addFile(string $pathToAdd, string $fileName = null): void
- {
- if (! $fileName) {
- $info = pathinfo($pathToAdd);
- $fileName = isset($info['extension']) ?
- $info['filename'].'.'.$info['extension'] :
- $info['filename'];
- }
-
- $this->repository->addFile($pathToAdd, $this->getInternalPath().$fileName);
- }
-
- /**
- * Add the file to the zip from content
- *
- * @param $filename
- * @param $content
- */
- private function addFromString($filename, $content): void
- {
- $this->repository->addFromString($this->getInternalPath().$filename, $content);
- }
-
- private function extractFilesInternal($path, callable $matchingMethod): void
- {
- $self = $this;
- $this->repository->each(function ($fileName) use ($path, $matchingMethod, $self) {
- $currentPath = $self->getCurrentFolderWithTrailingSlash();
- if (! empty($currentPath) && ! Str::startsWith($fileName, $currentPath)) {
- return;
- }
-
- $filename = str_replace($self->getInternalPath(), '', $fileName);
- if ($matchingMethod($filename)) {
- $self->extractOneFileInternal($fileName, $path);
- }
- });
- }
-
- /**
- * @param $fileName
- * @param $path
- *
- * @throws RuntimeException
- */
- private function extractOneFileInternal($fileName, $path): void
- {
- $tmpPath = str_replace($this->getInternalPath(), '', $fileName);
-
- //Prevent Zip traversal attacks
- if (str_contains($fileName, '../') || str_contains($fileName, '..\\')) {
- throw new RuntimeException('Special characters found within filenames');
- }
-
- // We need to create the directory first in case it doesn't exist
- $dir = pathinfo($path.DIRECTORY_SEPARATOR.$tmpPath, PATHINFO_DIRNAME);
- if (! $this->file->exists($dir) && ! $this->file->makeDirectory($dir, 0755, true, true)) {
- throw new RuntimeException('Failed to create folders');
- }
-
- $toPath = $path.DIRECTORY_SEPARATOR.$tmpPath;
- $fileStream = $this->getRepository()->getFileStream($fileName);
- $this->getFileHandler()->put($toPath, $fileStream);
- }
-}
diff --git a/catch/src/Support/helpers.php b/catch/src/Support/helpers.php
deleted file mode 100644
index e766fd6..0000000
--- a/catch/src/Support/helpers.php
+++ /dev/null
@@ -1,122 +0,0 @@
-unique()->filter(function ($path) {
- return is_dir($path);
- });
-
- if ($paths->isEmpty()) {
- return;
- }
-
- foreach ((new Finder())->in($paths->toArray())->files() as $command) {
- $command = $namespace.str_replace(['/', '.php'], ['\\', ''], Str::after($command->getRealPath(), $searchPath));
-
- if (is_subclass_of($command, Command::class) &&
- ! (new ReflectionClass($command))->isAbstract()) {
- Artisan::starting(function ($artisan) use ($command) {
- $artisan->resolve($command);
- });
- }
- }
- }
-}
-
-/**
- * table prefix
- */
-if (! function_exists('withTablePrefix')) {
- function withTablePrefix(string $table): string
- {
- return DB::connection()->getTablePrefix().$table;
- }
-}
-
-/**
- * get guard name
- */
-if (! function_exists('getGuardName')) {
- function getGuardName(): string
- {
- $guardKeys = array_keys(config('catch.auth.guards'));
-
- if (count($guardKeys)) {
- return $guardKeys[0];
- }
-
- return 'admin';
- }
-}
-
-/**
- * get table columns
- */
-if (! function_exists('getTableColumns')) {
- function getTableColumns(string $table): array
- {
- $SQL = 'desc '.withTablePrefix($table);
-
- $columns = [];
-
- foreach (DB::select($SQL) as $column) {
- $columns[] = $column->Field;
- }
-
- return $columns;
- }
-}
-
-if (! function_exists('dd_')) {
- /**
- * @param mixed ...$vars
- * @return never
- */
- function dd_(...$vars): never
- {
- if (! in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && ! headers_sent()) {
- header('HTTP/1.1 500 Internal Server Error');
- }
-
- header('Access-Control-Allow-Origin: *');
- header('Access-Control-Allow-Methods: *');
- header('Access-Control-Allow-Headers: *');
-
- foreach ($vars as $v) {
- VarDumper::dump($v);
- }
-
- exit(1);
- }
-}
diff --git a/catch/src/Traits/DB/BaseOperate.php b/catch/src/Traits/DB/BaseOperate.php
deleted file mode 100644
index 30f3076..0000000
--- a/catch/src/Traits/DB/BaseOperate.php
+++ /dev/null
@@ -1,288 +0,0 @@
-mergeCasts($this->mergeCasts);
- }
-
- if (property_exists($this, 'mergeHidden')) {
- $this->makeHidden($this->mergeHidden);
- }
- }
-
- /**
- * @return mixed
- */
- public function getList(): mixed
- {
- $queryBuilder = self::query()->select($this->fieldsInList)->quickSearch();
-
- if (in_array($this->sortField, $this->getFillable())) {
- $queryBuilder = $queryBuilder->orderBy($this->sortField, $this->sortDesc ? 'desc' : 'asc');
- }
-
- $queryBuilder = $queryBuilder->orderByDesc('id');
-
- if ($this->isPaginate) {
- return $queryBuilder->paginate(Request::get('limit', $this->perPage));
- }
-
-
-
- return $queryBuilder->get();
- }
-
- /**
- * save
- *
- * @param array $data
- * @return false|mixed
- */
- public function storeBy(array $data): mixed
- {
- if ($this->fill($this->filterData($data))->save()) {
- return $this->getKey();
- }
-
- return false;
- }
-
- /**
- * create
- *
- * @param array $data
- * @return false|mixed
- */
- public function createBy(array $data): mixed
- {
- $model = $this->newInstance();
-
- if ($model->fill($this->filterData($data))->save()) {
- return $model->getKey();
- }
-
- return false;
- }
-
- /**
- * update
- *
- * @param $id
- * @param array $data
- * @return mixed
- */
- public function updateBy($id, array $data): mixed
- {
- return $this->where($this->getKeyName(), $id)->update($this->filterData($data));
- }
-
- /**
- * filter data/ remove null && empty string
- *
- * @param array $data
- * @return array
- */
- protected function filterData(array $data): array
- {
- // 表单保存的数据集合
- $form = property_exists($this, 'form') ? $this->form : [];
-
- foreach ($data as $k => $val) {
- if (is_null($val) || (is_string($val) && ! $val)) {
- unset($data[$k]);
- }
-
- if (! empty($form) && ! in_array($k, $form)) {
- unset($data[$k]);
- }
- }
-
- return $data;
- }
-
-
- /**
- * get first by ID
- *
- * @param $id
- * @param string[] $columns
- * @return ?Model
- */
- public function firstBy($id, array $columns = ['*']): ?Model
- {
- return static::where($this->getKeyName(), $id)->first($columns);
- }
-
- /**
- * delete model
- *
- * @param $id
- * @param bool $force
- * @return bool|null
- */
- public function deleteBy($id, bool $force = false): ?bool
- {
- /* @var Model $model */
- $model = self::find($id);
-
- if ($force) {
- return $model->forceDelete();
- }
-
- return $model->delete();
- }
-
- /**
- * disable or enable
- *
- * @param $id
- * @param string $field
- * @return bool
- */
- public function disOrEnable($id, string $field = 'status'): bool
- {
- $model = self::firstBy($id);
-
- $model->{$field} = $model->{$field} == Status::Enable->value() ? Status::Disable->value() : Status::Enable->value();
-
- if ($model->save() && in_array($this->parentId, $this->getFillable())) {
- $this->updateChildren($id, $field, $model->{$field});
- }
-
- return true;
- }
-
-
- /**
- * 递归处理
- *
- * @param int|array $parentId
- * @param string $field
- * @param int $value
- */
- public function updateChildren(mixed $parentId, string $field, mixed $value): void
- {
- if (! $parentId instanceof Arrayable) {
- $parentId = Collection::make([$parentId]);
- }
-
- $childrenId = $this->whereIn('parent_id', $parentId)->pluck('id');
-
- if ($childrenId->count()) {
- if ($this->whereIn('parent_id', $parentId)->update([
- $field => $value
- ])) {
- $this->updateChildren($childrenId, $field, $value);
- }
- }
- }
-
- /**
- * alias field
- *
- * @param string|array $fields
- * @return string|array
- */
- public function aliasField(string|array $fields): string|array
- {
- $table = $this->getTable();
-
- if (is_string($fields)) {
- return "{$table}.{$fields}";
- }
-
- foreach ($fields as &$field) {
- $field = "{$table}.{$field}";
- }
-
- return $fields;
- }
-
-
- /**
- * get updated at column
- *
- * @return string|null
- */
- public function getUpdatedAtColumn(): ?string
- {
- $updatedAtColumn = parent::getUpdatedAtColumn();
-
- if (! in_array(parent::getUpdatedAtColumn(), $this->getFillable())) {
- $updatedAtColumn = null;
- }
-
- return $updatedAtColumn;
- }
-
- /**
- * get created at column
- *
- * @return string|null
- */
- public function getCreatedAtColumn(): ?string
- {
- $createdAtColumn = parent::getCreatedAtColumn();
-
- if (! in_array(parent::getUpdatedAtColumn(), $this->getFillable())) {
- $createdAtColumn = null;
- }
-
- return $createdAtColumn;
- }
-
- /**
- * whit form data
- *
- * @return $this
- */
- public function withoutForm(): static
- {
- if (property_exists($this, 'form') && ! empty($this->form)) {
- $this->form = [];
- }
-
- return $this;
- }
-}
diff --git a/catch/src/Traits/DB/ScopeTrait.php b/catch/src/Traits/DB/ScopeTrait.php
deleted file mode 100644
index 50c83a0..0000000
--- a/catch/src/Traits/DB/ScopeTrait.php
+++ /dev/null
@@ -1,20 +0,0 @@
-
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/modules/User/views/user/create.vue b/modules/User/views/user/create.vue
index 574d3a9..9f2a8fd 100644
--- a/modules/User/views/user/create.vue
+++ b/modules/User/views/user/create.vue
@@ -1,35 +1,53 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{{ $t('system.confirm') }}
@@ -42,10 +60,15 @@ import { useCreate } from '/admin/composables/curd/useCreate'
import { useShow } from '/admin/composables/curd/useShow'
import { onMounted, watch, ref } from 'vue'
+import http from '../../../../resources/admin/support/http'
const props = defineProps({
primary: String | Number,
api: String,
+ hasRoles: {
+ type: Boolean,
+ default: true,
+ },
})
const passwordRules = [
@@ -63,19 +86,31 @@ if (props.primary) {
passwordRules.shift()
}
-const { formData, form, loading, submitForm, isClose } = useCreate(props.api, props.primary)
+const { formData, form, loading, submitForm, close } = useCreate(props.api, props.primary)
+if (props.primary) {
+ useShow(props.api, props.primary, formData)
+}
const emit = defineEmits(['close'])
-watch(isClose, function (value) {
- if (value) {
- emit('close')
- }
-})
+
+const departments = ref()
+const jobs = ref()
+const roles = ref()
onMounted(() => {
- if (props.primary) {
- useShow(props.api, props.primary).then(r => {
- formData.value = r.data
+ close(() => emit('close'))
+
+ if (props.hasRoles) {
+ http.get('permissions/roles').then(r => {
+ roles.value = r.data.data
+ })
+
+ http.get('permissions/departments').then(r => {
+ departments.value = r.data.data
+ })
+
+ http.get('permissions/jobs').then(r => {
+ jobs.value = r.data.data
})
}
})
diff --git a/modules/User/views/user/index.vue b/modules/User/views/user/index.vue
index 44abf5f..d88b52e 100644
--- a/modules/User/views/user/index.vue
+++ b/modules/User/views/user/index.vue
@@ -1,5 +1,7 @@
-
+
+
+
@@ -13,8 +15,8 @@
-
-
+
+
@@ -27,7 +29,7 @@
-
+
@@ -40,36 +42,25 @@
+