Skip to content

Commit

Permalink
Fix driver expects gateway but object provided
Browse files Browse the repository at this point in the history
  • Loading branch information
zingimmick committed Aug 16, 2020
1 parent 5d033ff commit 391fbca
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/Connectors/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,28 @@ public function connect(array $config)
}

$driverClass = $config['driver'];
$this->driver = $this->resolveDriver($driverClass, $config);

return $this;
}

/**
* Get gateway by class name.
*
* @param string $driverClass
* @param array $config
*
* @throws \Zing\LaravelSms\Exceptions\InvalidArgumentException
*
* @return \Overtrue\EasySms\Contracts\GatewayInterface
*/
protected function resolveDriver(string $driverClass, array $config): GatewayInterface
{
if (! class_exists($driverClass) || ! in_array(GatewayInterface::class, class_implements($driverClass), true)) {
throw new InvalidArgumentException("Unsupported driver [{$driverClass}].");
}

$this->driver = new $driverClass($config);

return $this;
return new $driverClass($config);
}

/**
Expand Down

0 comments on commit 391fbca

Please sign in to comment.