forked from overtrue/easy-sms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
644 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ composer.lock | |
.subsplit | ||
.php_cs.cache | ||
.idea | ||
index.php | ||
config.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/easy-sms. | ||
* (c) overtrue <[email protected]> | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Overtrue\EasySms\Contracts; | ||
|
||
/** | ||
* Class GatewayInterface | ||
* Class GatewayInterface. | ||
*/ | ||
interface GatewayInterface | ||
{ | ||
|
@@ -17,4 +24,4 @@ interface GatewayInterface | |
* @return mixed | ||
*/ | ||
public function send($to, $template, array $data = []); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/easy-sms. | ||
* (c) overtrue <[email protected]> | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Overtrue\EasySms; | ||
|
||
use Closure; | ||
|
@@ -9,7 +16,7 @@ | |
use RuntimeException; | ||
|
||
/** | ||
* Class EasySms | ||
* Class EasySms. | ||
*/ | ||
class EasySms | ||
{ | ||
|
@@ -50,7 +57,7 @@ public function __construct(array $config) | |
/** | ||
* Create a gateway. | ||
* | ||
* @param string $name | ||
* @param string $name | ||
* | ||
* @return \Overtrue\EasySms\Contracts\GatewayInterface | ||
*/ | ||
|
@@ -85,7 +92,7 @@ public function extend($name, Closure $callback) | |
* | ||
* @return string | ||
* | ||
* @throws if no default gateway configured. | ||
* @throws if no default gateway configured | ||
*/ | ||
public function getDefaultGateway() | ||
{ | ||
|
@@ -114,6 +121,7 @@ public function setDefaultGateway($name) | |
* Create a new driver instance. | ||
* | ||
* @param string $name | ||
* | ||
* @throws \InvalidArgumentException | ||
* | ||
* @return mixed | ||
|
@@ -123,8 +131,12 @@ protected function createGateway($name) | |
if (isset($this->customCreators[$name])) { | ||
$gateway = $this->callCustomCreator($name); | ||
} else { | ||
$name = $this->formatGatewayClassName($name); | ||
$gateway = $this->makeGateway($name, $this->config->get($name, [])); | ||
$className = $this->formatGatewayClassName($name); | ||
$config = array_merge( | ||
['signature' => $this->config->get('signature', '')], | ||
$this->config->get("gateways.{$name}", []) | ||
); | ||
$gateway = $this->makeGateway($className, $config); | ||
} | ||
|
||
if (!($gateway instanceof GatewayInterface)) { | ||
|
@@ -205,4 +217,4 @@ public function __call($method, $parameters) | |
{ | ||
return call_user_func_array([$this->gateway(), $method], $parameters); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/easy-sms. | ||
* (c) overtrue <[email protected]> | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Overtrue\EasySms\Gateways; | ||
|
||
/** | ||
* Class ErrorLogGateway. | ||
*/ | ||
class ErrorLogGateway extends Gateway | ||
{ | ||
/** | ||
* Send a short message. | ||
* | ||
* @param string|int $to | ||
* @param string $message | ||
* @param array $data | ||
* | ||
* @return mixed | ||
*/ | ||
public function send($to, $message, array $data = []) | ||
{ | ||
$message = sprintf( | ||
"[%s] to: %s, message: \"%s\", data: %s\n", | ||
date('Y-m-d H:i:s'), | ||
$to, | ||
addcslashes($message, '"'), | ||
json_encode($data) | ||
); | ||
|
||
return error_log($message, 3, $this->config->get('file', ini_get('error_log'))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/easy-sms. | ||
* (c) overtrue <[email protected]> | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Overtrue\EasySms\Gateways; | ||
|
||
use Overtrue\EasySms\Contracts\GatewayInterface; | ||
use Overtrue\EasySms\Support\Config; | ||
|
||
/** | ||
* Class Gateway | ||
*/ | ||
abstract class Gateway implements GatewayInterface | ||
{ | ||
const DEFAULT_TIMEOUT = 5.0; | ||
|
||
/** | ||
* @var \Overtrue\EasySms\Support\Config | ||
*/ | ||
protected $config; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $baseUri; | ||
|
||
/** | ||
* @var float | ||
*/ | ||
protected $timeout; | ||
|
||
/** | ||
* Gateway constructor. | ||
* | ||
* @param array $config | ||
*/ | ||
public function __construct(array $config) | ||
{ | ||
$this->config = new Config($config); | ||
} | ||
|
||
/** | ||
* Return base uri. | ||
* | ||
* @return string | ||
*/ | ||
public function getBaseUri() | ||
{ | ||
return $this->baseUri; | ||
} | ||
|
||
/** | ||
* Return timeout. | ||
* | ||
* @return int|mixed | ||
*/ | ||
public function getTimeout() | ||
{ | ||
return $this->timeout ?: $this->config->get('timeout', self::DEFAULT_TIMEOUT); | ||
} | ||
|
||
/** | ||
* Set timeout. | ||
* | ||
* @param int $timeout | ||
* | ||
* @return $this | ||
*/ | ||
public function timeout($timeout) | ||
{ | ||
$this->timeout = floatval($timeout); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return \Overtrue\EasySms\Support\Config | ||
*/ | ||
public function getConfig() | ||
{ | ||
return $this->config; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.