Skip to content

Commit

Permalink
feat: support php 7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
thatsgolden committed Jul 14, 2024
1 parent f7be99e commit 1615a6b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,24 @@ 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)
{
$flag = false;
foreach ($keys as $key) {
$flag = trim($settings->get(self::getSettingPath($key), '')) === '';
if($flag) break;
if ($flag) break;
}
return $flag;
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 1615a6b

Please sign in to comment.