Skip to content

Commit

Permalink
Fix bug and compatible with thinkphp > 6.0
Browse files Browse the repository at this point in the history
Fixed bug, compatible with thinkphp version greater than 6.0 when confing driver is used by default
  • Loading branch information
isszz authored Jun 29, 2023
1 parent b07f221 commit 9155572
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9155572

Please sign in to comment.