From 91555729b15216ec7cddfcbb95dabb231f96f226 Mon Sep 17 00:00:00 2001 From: isszz Date: Thu, 29 Jun 2023 20:25:40 +0800 Subject: [PATCH] Fix bug and compatible with thinkphp > 6.0 Fixed bug, compatible with thinkphp version greater than 6.0 when confing driver is used by default --- src/Captcha.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Captcha.php b/src/Captcha.php index bdaaf66..e9552a6 100644 --- a/src/Captcha.php +++ b/src/Captcha.php @@ -374,21 +374,23 @@ public function configDrive(string $config): self */ public function config(string|null $name = null, string|null $defaultValue = null): mixed { - if (!is_object($this->configDrive) && !is_subclass_of($this->configDrive, Config::class)) { - - if(!class_exists(\think\App::class) || strpos(\think\App::VERSION, '6.0') === false) { - throw new CaptchaException($this->lang()->get('Config driver :driver does not exist.', [ - 'driver' => is_object($this->configDrive) ? get_class($this->configDrive) : $this->configDrive - ])); + // Setting the default drive + if (!is_object($this->configDrive)) { + if(class_exists(\think\App::class) && version_compare(\think\App::VERSION, '6.0', '>=')) { + // Default config drive is thinkphp6.x + $this->configDrive = new \isszz\captcha\rotate\config\Think(); + } else { + throw new CaptchaException($this->lang()->get('Please set config Drive first.')); } + } - // Default config drive is thinkphp6.0.x - $this->configDrive = new \isszz\captcha\rotate\config\Think(); + if(is_object($this->configDrive) && !is_subclass_of($this->configDrive, Config::class)) { + throw new CaptchaException($this->lang()->get('Config driver must inherit from isszz\captcha\rotate\Config')); } + // Merge configuration content $config = array_merge($this->config, $this->configDrive->get('rotateCaptcha')); - if(is_null($name)) { return $config; }