Skip to content

Commit

Permalink
PHP 8.1 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
canerdogan committed Jul 11, 2024
1 parent 34881e4 commit 1a547fb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"type": "library",
"license": "MIT",
"require": {
"php": ">=7.0",
"guzzlehttp/guzzle": "^6.2",
"php": "^8.0",
"guzzlehttp/guzzle": "^7.8",
"ext-simplexml": "*",
"ext-json": "*"
},
Expand Down
38 changes: 25 additions & 13 deletions src/Sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,39 @@

class Sms
{

private $driver;

public function __construct($driver = false, $config = [])

public function __construct($driver = null, array $config = [])
{
if ($config === [] && function_exists('config')) {
$smsConfig = config('sms');
}

if ($driver == false) {
$this->configureDriver($driver, $config);
}


public function driver($driver = null, array $config = [])
{

$this->configureDriver($driver, $config);
}


private function configureDriver(?string $driver, array $config)
{

$smsConfig = $config === [] && function_exists('config') ? config('sms') : [];

if ($driver === null && !empty($smsConfig)) {
$driver = $smsConfig['default_driver'];
}

if ($config === [] && function_exists('config')) {
$config = config('sms.'.$driver);
$config = config('sms.' . $driver);
}

$this->driver($driver, $config);
}

public function driver($driver, $config)
{
try {
$driverClass = "\\Mukellef\\Sms\\Drivers\\{$driver}";
$driverClass = "\\Mukellef\\Sms\\Drivers\\{$driver}";
$this->driver = new $driverClass($driver, $config);
} catch (DriverConfigurationException $e) {
throw new DriverConfigurationException($e);
Expand All @@ -38,13 +48,15 @@ public function driver($driver, $config)
}
}


/**
* @param $message string
* @param $numbers array
* @param $header string SMS HEADER
*/
public function send($message, $numbers, $header, $valid_for = '24:00')
public function send(string $message, array $numbers, string $header, ?string $valid_for = '24:00'): void
{

$this->driver->send($message, $numbers, $header, $valid_for);
}
}

0 comments on commit 1a547fb

Please sign in to comment.