From 1615a6b632a44dbb1d249c150023a9a8e18d7351 Mon Sep 17 00:00:00 2001 From: Golden <96641851+thatsgolden@users.noreply.github.com> Date: Sun, 14 Jul 2024 20:36:43 +0800 Subject: [PATCH] feat: support php 7.3 --- src/Utils.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Utils.php b/src/Utils.php index ac39301..5f567ea 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -18,14 +18,16 @@ class Utils { const PREFIX = 'ffans-geetest'; - public static function isExtensionSetup(SettingsRepositoryInterface $settings, string $type = null): bool + private static $configKeys = [ + ContextEvent::Signup => [ContextEvent::Signup . '.product', ContextEvent::Signup . '.id', ContextEvent::Signup . '.key'], + ContextEvent::Login => [ContextEvent::Login . '.product', ContextEvent::Login . '.id', ContextEvent::Login . '.key'], + ContextEvent::Forgot => [ContextEvent::Forgot . '.product', ContextEvent::Forgot . '.id', ContextEvent::Forgot . '.key'], + 'default' => ['product_service', 'product', 'id', 'key'], + ]; + + public static function isExtensionSetup(SettingsRepositoryInterface $settings, string $type = 'default'): bool { - return match ($type) { - ContextEvent::Signup => !self::isNil($settings, [ContextEvent::Signup . '.product', ContextEvent::Signup . '.id', ContextEvent::Signup . '.key']), - ContextEvent::Login => !self::isNil($settings, [ContextEvent::Login . '.product', ContextEvent::Login . '.id', ContextEvent::Login . '.key']), - ContextEvent::Forgot => !self::isNil($settings, [ContextEvent::Forgot . '.product', ContextEvent::Forgot . '.id', ContextEvent::Forgot . '.key']), - default => !self::isNil($settings, ['product_service', 'product', 'id', 'key']), - }; + return !self::isNil($settings, self::$configKeys[$type]); } private static function isNil(SettingsRepositoryInterface $settings, array $keys) @@ -33,7 +35,7 @@ private static function isNil(SettingsRepositoryInterface $settings, array $keys $flag = false; foreach ($keys as $key) { $flag = trim($settings->get(self::getSettingPath($key), '')) === ''; - if($flag) break; + if ($flag) break; } return $flag; } @@ -64,8 +66,9 @@ public static function logInfo(string $message, mixed $details = null) resolve('log')->info('[FFans\GeeTest] ' . $message); $details && resolve('log')->info(var_export($details, true)); } + public static function translate(string $key) { - return resolve('translator')->trans(self::PREFIX.'.'.$key); + return resolve('translator')->trans(self::PREFIX . '.' . $key); } }