Browse Source

系统参数存储重构

兔姬桑 4 năm trước cách đây
mục cha
commit
152b8f65be

+ 0 - 38
app/Components/CaptchaVerify.php

@@ -1,38 +0,0 @@
-<?php
-
-namespace App\Components;
-
-/**
- * Class CaptchaVerify 验证码
- */
-class CaptchaVerify
-{
-    //从后台获取 hcaptcha_sitekey 和 hcaptcha_secret
-    public static function hCaptchaGetConfig(): array
-    {
-        return [
-            'sitekey' => sysConfig('hcaptcha_sitekey'),
-            'secret' => sysConfig('hcaptcha_secret'),
-            'options' => [],
-        ];
-    }
-
-    //从后台获取 Geetest_id 和 Geetest_key
-    public static function geetestCaptchaGetConfig(): array
-    {
-        return [
-            'geetest_id' => sysConfig('geetest_id'),
-            'geetest_key' => sysConfig('geetest_key'),
-        ];
-    }
-
-    //从后台获取 google_captcha_sitekey 和 google_captcha_secret
-    public static function googleCaptchaGetConfig(): array
-    {
-        return [
-            'sitekey' => sysConfig('google_captcha_sitekey'),
-            'secret' => sysConfig('google_captcha_secret'),
-            'options' => [],
-        ];
-    }
-}

+ 0 - 49
app/Components/Helpers.php

@@ -144,55 +144,6 @@ class Helpers
         return $config->name ?? 'plain';
     }
 
-    // 获取系统配置
-    public static function cacheSysConfig($name)
-    {
-        $notifications = [
-            'account_expire_notification',
-            'data_anomaly_notification',
-            'data_exhaust_notification',
-            'node_blocked_notification',
-            'node_daily_notification',
-            'node_offline_notification',
-            'password_reset_notification',
-            'payment_received_notification',
-            'ticket_closed_notification',
-            'ticket_created_notification',
-            'ticket_replied_notification',
-        ];
-
-        if ($name === 'is_onlinePay') {
-            $value = sysConfig('is_AliPay') || sysConfig('is_QQPay') || sysConfig('is_WeChatPay') || sysConfig('is_otherPay');
-            Cache::tags('sysConfig')->put('is_onlinePay', $value);
-        } else {
-            if (in_array($name, $notifications, true)) {
-                $value = self::setChannel(json_decode(Config::find($name)->value, true));
-            } else {
-                $value = Config::find($name)->value;
-            }
-            Cache::tags('sysConfig')->put($name, $value ?? false);
-        }
-
-        return $value;
-    }
-
-    private static function setChannel(array $channels)
-    {
-        $options = [
-            'telegram'   => TelegramChannel::class,
-            'beary'      => BearyChatChannel::class,
-            'bark'       => BarkChannel::class,
-            'serverChan' => ServerChanChannel::class,
-        ];
-        foreach ($options as $option => $str) {
-            if (($key = array_search($option, $channels, true)) !== false) {
-                $channels[$key] = $str;
-            }
-        }
-
-        return $channels;
-    }
-
     public static function daysToNow($date): int
     {
         return (new DateTime())->diff(new DateTime($date))->days;

+ 0 - 7
app/Observers/ConfigObserver.php

@@ -11,13 +11,6 @@ class ConfigObserver
 {
     public function updated(Config $config): void
     {
-        if (in_array($config->name, ['is_AliPay', 'is_QQPay', 'is_WeChatPay', 'is_otherPay']) && Cache::tags('sysConfig')->has('is_onlinePay')) {
-            Cache::tags('sysConfig')->put($config->name, $config->value);
-            Helpers::cacheSysConfig('is_onlinePay'); // 如果在线支付方式出现变动,改变 在线支付 设置状态
-        } else {
-            Helpers::cacheSysConfig($config->name); // 更新系统参数缓存
-        }
-
         // 域名出现变动,更新路由设定
         if (in_array($config->name, ['subscribe_domain', 'web_api_url', 'website_callback_url'])) {
             if (config('app.debug')) {

+ 1 - 1
app/Providers/AppServiceProvider.php

@@ -10,7 +10,6 @@ use App\Models\UserGroup;
 use App\Observers\ConfigObserver;
 use App\Observers\NodeObserver;
 use App\Observers\OrderObserver;
-use App\Observers\RuleGroupObserver;
 use App\Observers\UserGroupObserver;
 use App\Observers\UserObserver;
 use Illuminate\Support\ServiceProvider;
@@ -31,6 +30,7 @@ class AppServiceProvider extends ServiceProvider
             $this->app->register(TelescopeServiceProvider::class);
             $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
         }
+        $this->app->register(SettingServiceProvider::class);
     }
 
     /**

+ 86 - 0
app/Providers/SettingServiceProvider.php

@@ -0,0 +1,86 @@
+<?php
+
+namespace App\Providers;
+
+use App\Channels\BarkChannel;
+use App\Channels\ServerChanChannel;
+use App\Models\Config;
+use Illuminate\Support\ServiceProvider;
+use NotificationChannels\BearyChat\BearyChatChannel;
+use NotificationChannels\Telegram\TelegramChannel;
+
+class SettingServiceProvider extends ServiceProvider
+{
+    /**
+     * Bootstrap services.
+     *
+     * @return void
+     */
+    public function boot()
+    {
+        $toApp = collect([
+            'geetest_id'             => 'geetest.id',
+            'geetest_key'            => 'geetest.key',
+            'google_captcha_secret'  => 'NoCaptcha.secret',
+            'google_captcha_sitekey' => 'NoCaptcha.sitekey',
+            'hcaptcha_secret'        => 'HCaptcha.secret',
+            'hcaptcha_sitekey'       => 'HCaptcha.sitekey',
+        ]);
+
+        $notifications = collect([
+            'account_expire_notification',
+            'data_anomaly_notification',
+            'data_exhaust_notification',
+            'node_blocked_notification',
+            'node_daily_notification',
+            'node_offline_notification',
+            'password_reset_notification',
+            'payment_received_notification',
+            'ticket_closed_notification',
+            'ticket_created_notification',
+            'ticket_replied_notification',
+        ]);
+
+        $settings = Config::all();
+
+        $modified = $settings
+            ->whereNotIn('name', $toApp->keys()->merge($notifications)) // 设置一般系统选项
+            ->pluck('value', 'name')
+            ->merge($settings->whereIn('name', $notifications)->pluck('value', 'name')->map(function ($item) {
+                return self::setChannel(json_decode($item, true) ?? []);
+            })) // 设置通知相关选项
+            ->merge(collect(['is_onlinePay' => $settings->whereIn('name', ['is_AliPay', 'is_QQPay', 'is_WeChatPay', 'is_otherPay'])->pluck('value')->filter()->isNotEmpty(),
+            ])) // 设置在线支付开关
+            ->sortKeys();
+
+        config(['settings' => $modified]); // 设置系统参数
+
+        $settings->whereIn('name', $toApp->keys())->pluck('value', 'name')->each(function ($item, $key) use ($toApp) {
+            config([$toApp[$key] => $item]); // 设置PHP软件包相关配置
+        });
+
+        collect([
+            'website_name' => 'app.name',
+            'website_url'  => 'app.url',
+        ])->each(function ($item, $key) {
+            config([$item => config('settings.'.$key)]); // 设置APP有关的选项
+        });
+    }
+
+    private static function setChannel(array $channels)
+    {
+        $options = [
+            'telegram'   => TelegramChannel::class,
+            'beary'      => BearyChatChannel::class,
+            'bark'       => BarkChannel::class,
+            'serverChan' => ServerChanChannel::class,
+        ];
+        foreach ($options as $option => $str) {
+            if (($key = array_search($option, $channels, true)) !== false) {
+                $channels[$key] = $str;
+            }
+        }
+
+        return $channels;
+    }
+}

+ 1 - 8
app/helpers.php

@@ -1,7 +1,5 @@
 <?php
 
-use App\Components\Helpers;
-
 define('KB', 1024);
 define('MB', 1048576);
 define('GB', 1073741824);
@@ -92,11 +90,6 @@ if (! function_exists('filterEmoji')) {
 if (! function_exists('sysConfig')) {
     function sysConfig($name)
     {
-        $ret = Cache::tags('sysConfig')->get($name);
-        if (is_null($ret)) {
-            return Helpers::cacheSysConfig($name);
-        }
-
-        return $ret;
+        return config('settings.'.$name);
     }
 }

+ 68 - 64
composer.lock

@@ -64,26 +64,26 @@
         },
         {
             "name": "brick/math",
-            "version": "0.9.1",
+            "version": "0.9.2",
             "source": {
                 "type": "git",
                 "url": "https://github.com/brick/math.git",
-                "reference": "283a40c901101e66de7061bd359252c013dcc43c"
+                "reference": "dff976c2f3487d42c1db75a3b180e2b9f0e72ce0"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/brick/math/zipball/283a40c901101e66de7061bd359252c013dcc43c",
-                "reference": "283a40c901101e66de7061bd359252c013dcc43c",
+                "url": "https://api.github.com/repos/brick/math/zipball/dff976c2f3487d42c1db75a3b180e2b9f0e72ce0",
+                "reference": "dff976c2f3487d42c1db75a3b180e2b9f0e72ce0",
                 "shasum": ""
             },
             "require": {
                 "ext-json": "*",
-                "php": "^7.1|^8.0"
+                "php": "^7.1 || ^8.0"
             },
             "require-dev": {
                 "php-coveralls/php-coveralls": "^2.2",
-                "phpunit/phpunit": "^7.5.15|^8.5",
-                "vimeo/psalm": "^3.5"
+                "phpunit/phpunit": "^7.5.15 || ^8.5 || ^9.0",
+                "vimeo/psalm": "4.3.2"
             },
             "type": "library",
             "autoload": {
@@ -108,7 +108,7 @@
             ],
             "support": {
                 "issues": "https://github.com/brick/math/issues",
-                "source": "https://github.com/brick/math/tree/master"
+                "source": "https://github.com/brick/math/tree/0.9.2"
             },
             "funding": [
                 {
@@ -116,7 +116,7 @@
                     "type": "tidelift"
                 }
             ],
-            "time": "2020-08-18T23:57:15+00:00"
+            "time": "2021-01-20T22:51:39+00:00"
         },
         {
             "name": "composer/ca-bundle",
@@ -1933,16 +1933,16 @@
         },
         {
             "name": "laravel/framework",
-            "version": "v7.30.3",
+            "version": "v7.30.4",
             "source": {
                 "type": "git",
                 "url": "https://github.com/laravel/framework.git",
-                "reference": "28481951106e75cf8c5a8b24100059fa327df1ef"
+                "reference": "9dd38140dc2924daa1a020a3d7a45f9ceff03df3"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/laravel/framework/zipball/28481951106e75cf8c5a8b24100059fa327df1ef",
-                "reference": "28481951106e75cf8c5a8b24100059fa327df1ef",
+                "url": "https://api.github.com/repos/laravel/framework/zipball/9dd38140dc2924daa1a020a3d7a45f9ceff03df3",
+                "reference": "9dd38140dc2924daa1a020a3d7a45f9ceff03df3",
                 "shasum": ""
             },
             "require": {
@@ -2091,7 +2091,7 @@
                 "issues": "https://github.com/laravel/framework/issues",
                 "source": "https://github.com/laravel/framework"
             },
-            "time": "2021-01-15T15:38:30+00:00"
+            "time": "2021-01-21T14:10:48+00:00"
         },
         {
             "name": "laravel/tinker",
@@ -2654,20 +2654,20 @@
         },
         {
             "name": "markbaker/matrix",
-            "version": "2.0.0",
+            "version": "2.1.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/MarkBaker/PHPMatrix.git",
-                "reference": "9567d9c4c519fbe40de01dbd1e4469dbbb66f46a"
+                "reference": "35a2d1a919a1de732402f694925168c53c17c838"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/9567d9c4c519fbe40de01dbd1e4469dbbb66f46a",
-                "reference": "9567d9c4c519fbe40de01dbd1e4469dbbb66f46a",
+                "url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/35a2d1a919a1de732402f694925168c53c17c838",
+                "reference": "35a2d1a919a1de732402f694925168c53c17c838",
                 "shasum": ""
             },
             "require": {
-                "php": "^7.2 || ^8.0"
+                "php": "^7.1 || ^8.0"
             },
             "require-dev": {
                 "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
@@ -2685,22 +2685,22 @@
                     "Matrix\\": "classes/src/"
                 },
                 "files": [
-                    "classes/src/functions/adjoint.php",
-                    "classes/src/functions/antidiagonal.php",
-                    "classes/src/functions/cofactors.php",
-                    "classes/src/functions/determinant.php",
-                    "classes/src/functions/diagonal.php",
-                    "classes/src/functions/identity.php",
-                    "classes/src/functions/inverse.php",
-                    "classes/src/functions/minors.php",
-                    "classes/src/functions/trace.php",
-                    "classes/src/functions/transpose.php",
-                    "classes/src/operations/add.php",
-                    "classes/src/operations/directsum.php",
-                    "classes/src/operations/subtract.php",
-                    "classes/src/operations/multiply.php",
-                    "classes/src/operations/divideby.php",
-                    "classes/src/operations/divideinto.php"
+                    "classes/src/Functions/adjoint.php",
+                    "classes/src/Functions/antidiagonal.php",
+                    "classes/src/Functions/cofactors.php",
+                    "classes/src/Functions/determinant.php",
+                    "classes/src/Functions/diagonal.php",
+                    "classes/src/Functions/identity.php",
+                    "classes/src/Functions/inverse.php",
+                    "classes/src/Functions/minors.php",
+                    "classes/src/Functions/trace.php",
+                    "classes/src/Functions/transpose.php",
+                    "classes/src/Operations/add.php",
+                    "classes/src/Operations/directsum.php",
+                    "classes/src/Operations/subtract.php",
+                    "classes/src/Operations/multiply.php",
+                    "classes/src/Operations/divideby.php",
+                    "classes/src/Operations/divideinto.php"
                 ]
             },
             "notification-url": "https://packagist.org/downloads/",
@@ -2722,9 +2722,9 @@
             ],
             "support": {
                 "issues": "https://github.com/MarkBaker/PHPMatrix/issues",
-                "source": "https://github.com/MarkBaker/PHPMatrix/tree/PHP8"
+                "source": "https://github.com/MarkBaker/PHPMatrix/tree/2.1.1"
             },
-            "time": "2020-08-28T17:11:00+00:00"
+            "time": "2021-01-21T13:53:09+00:00"
         },
         {
             "name": "maxmind-db/reader",
@@ -4208,16 +4208,16 @@
         },
         {
             "name": "ramsey/collection",
-            "version": "1.1.1",
+            "version": "1.1.3",
             "source": {
                 "type": "git",
                 "url": "https://github.com/ramsey/collection.git",
-                "reference": "24d93aefb2cd786b7edd9f45b554aea20b28b9b1"
+                "reference": "28a5c4ab2f5111db6a60b2b4ec84057e0f43b9c1"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/ramsey/collection/zipball/24d93aefb2cd786b7edd9f45b554aea20b28b9b1",
-                "reference": "24d93aefb2cd786b7edd9f45b554aea20b28b9b1",
+                "url": "https://api.github.com/repos/ramsey/collection/zipball/28a5c4ab2f5111db6a60b2b4ec84057e0f43b9c1",
+                "reference": "28a5c4ab2f5111db6a60b2b4ec84057e0f43b9c1",
                 "shasum": ""
             },
             "require": {
@@ -4227,19 +4227,19 @@
                 "captainhook/captainhook": "^5.3",
                 "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
                 "ergebnis/composer-normalize": "^2.6",
-                "fzaninotto/faker": "^1.5",
+                "fakerphp/faker": "^1.5",
                 "hamcrest/hamcrest-php": "^2",
-                "jangregor/phpstan-prophecy": "^0.6",
+                "jangregor/phpstan-prophecy": "^0.8",
                 "mockery/mockery": "^1.3",
                 "phpstan/extension-installer": "^1",
                 "phpstan/phpstan": "^0.12.32",
                 "phpstan/phpstan-mockery": "^0.12.5",
                 "phpstan/phpstan-phpunit": "^0.12.11",
-                "phpunit/phpunit": "^8.5",
+                "phpunit/phpunit": "^8.5 || ^9",
                 "psy/psysh": "^0.10.4",
                 "slevomat/coding-standard": "^6.3",
                 "squizlabs/php_codesniffer": "^3.5",
-                "vimeo/psalm": "^3.12.2"
+                "vimeo/psalm": "^4.4"
             },
             "type": "library",
             "autoload": {
@@ -4269,15 +4269,19 @@
             ],
             "support": {
                 "issues": "https://github.com/ramsey/collection/issues",
-                "source": "https://github.com/ramsey/collection/tree/1.1.1"
+                "source": "https://github.com/ramsey/collection/tree/1.1.3"
             },
             "funding": [
                 {
                     "url": "https://github.com/ramsey",
                     "type": "github"
+                },
+                {
+                    "url": "https://tidelift.com/funding/github/packagist/ramsey/collection",
+                    "type": "tidelift"
                 }
             ],
-            "time": "2020-09-10T20:58:17+00:00"
+            "time": "2021-01-21T17:40:04+00:00"
         },
         {
             "name": "ramsey/uuid",
@@ -4634,16 +4638,16 @@
         },
         {
             "name": "stripe/stripe-php",
-            "version": "v7.68.0",
+            "version": "v7.69.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/stripe/stripe-php.git",
-                "reference": "36b10e1f0e9d973f00f802bbd098bce85d0438e4"
+                "reference": "6716cbc4ebf8cba7d45374a059c7c6e5bf53277d"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/stripe/stripe-php/zipball/36b10e1f0e9d973f00f802bbd098bce85d0438e4",
-                "reference": "36b10e1f0e9d973f00f802bbd098bce85d0438e4",
+                "url": "https://api.github.com/repos/stripe/stripe-php/zipball/6716cbc4ebf8cba7d45374a059c7c6e5bf53277d",
+                "reference": "6716cbc4ebf8cba7d45374a059c7c6e5bf53277d",
                 "shasum": ""
             },
             "require": {
@@ -4689,9 +4693,9 @@
             ],
             "support": {
                 "issues": "https://github.com/stripe/stripe-php/issues",
-                "source": "https://github.com/stripe/stripe-php/tree/v7.68.0"
+                "source": "https://github.com/stripe/stripe-php/tree/v7.69.0"
             },
-            "time": "2021-01-15T00:38:28+00:00"
+            "time": "2021-01-22T03:21:13+00:00"
         },
         {
             "name": "swiftmailer/swiftmailer",
@@ -7219,16 +7223,16 @@
         },
         {
             "name": "vlucas/phpdotenv",
-            "version": "v4.1.8",
+            "version": "v4.2.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/vlucas/phpdotenv.git",
-                "reference": "572af79d913627a9d70374d27a6f5d689a35de32"
+                "reference": "da64796370fc4eb03cc277088f6fede9fde88482"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/572af79d913627a9d70374d27a6f5d689a35de32",
-                "reference": "572af79d913627a9d70374d27a6f5d689a35de32",
+                "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/da64796370fc4eb03cc277088f6fede9fde88482",
+                "reference": "da64796370fc4eb03cc277088f6fede9fde88482",
                 "shasum": ""
             },
             "require": {
@@ -7240,7 +7244,7 @@
                 "bamarni/composer-bin-plugin": "^1.4.1",
                 "ext-filter": "*",
                 "ext-pcre": "*",
-                "phpunit/phpunit": "^4.8.35 || ^5.7.27 || ^6.5.6 || ^7.0"
+                "phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20"
             },
             "suggest": {
                 "ext-filter": "Required to use the boolean validator.",
@@ -7281,7 +7285,7 @@
             ],
             "support": {
                 "issues": "https://github.com/vlucas/phpdotenv/issues",
-                "source": "https://github.com/vlucas/phpdotenv/tree/4.1"
+                "source": "https://github.com/vlucas/phpdotenv/tree/v4.2.0"
             },
             "funding": [
                 {
@@ -7293,7 +7297,7 @@
                     "type": "tidelift"
                 }
             ],
-            "time": "2020-07-14T19:22:52+00:00"
+            "time": "2021-01-20T15:11:48+00:00"
         },
         {
             "name": "voku/portable-ascii",
@@ -11865,12 +11869,12 @@
             "version": "1.9.1",
             "source": {
                 "type": "git",
-                "url": "https://github.com/webmozart/assert.git",
+                "url": "https://github.com/webmozarts/assert.git",
                 "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389",
+                "url": "https://api.github.com/repos/webmozarts/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389",
                 "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389",
                 "shasum": ""
             },
@@ -11908,8 +11912,8 @@
                 "validate"
             ],
             "support": {
-                "issues": "https://github.com/webmozart/assert/issues",
-                "source": "https://github.com/webmozart/assert/tree/master"
+                "issues": "https://github.com/webmozarts/assert/issues",
+                "source": "https://github.com/webmozarts/assert/tree/1.9.1"
             },
             "time": "2020-07-08T17:02:28+00:00"
         }

+ 1 - 1
config/HCaptcha.php

@@ -3,7 +3,7 @@
 return [
     'secret' => env('HCAPTCHA_SECRET'),
     'sitekey' => env('HCAPTCHA_SITEKEY'),
-    'server-get-config' => true,
+    'server-get-config' => false,
     'options' => [
         'timeout' => 30,
     ],

+ 1 - 1
config/NoCaptcha.php

@@ -3,7 +3,7 @@
 return [
     'secret' => env('NOCAPTCHA_SECRET'),
     'sitekey' => env('NOCAPTCHA_SITEKEY'),
-    'server-get-config' => true,
+    'server-get-config' => false,
     'options' => [
         'timeout' => 30,
     ],

+ 1 - 1
config/geetest.php

@@ -2,7 +2,7 @@
 
 return [
     'lang' => app()->getLocale(),
-    'server-get-config' => true,
+    'server-get-config' => false,
     'id' => env('GEETEST_ID'),
     'key' => env('GEETEST_KEY'),
     'url' => '/geetest',