From c6dab6b2a527646a235d323a347a0b54c9553dd3 Mon Sep 17 00:00:00 2001 From: zhouyangyang Date: Sun, 10 Apr 2022 00:14:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ConfigProvider.php | 2 +- src/Events/SmsMessageSending.php | 10 +--- .../StrategicallySendMessageException.php | 2 +- src/PendingSms.php | 57 +++++++++++-------- src/QueuedSmsableJob.php | 4 +- 5 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 1776e44..8db8683 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -31,7 +31,7 @@ class ConfigProvider 'publish' => [ [ 'id' => 'config', - 'description' => 'The config for hyperf-ext/sms.', + 'description' => 'The config for zyimm/sms.', 'source' => __DIR__ . '/../publish/sms.php', 'destination' => BASE_PATH . '/config/autoload/sms.php', ], diff --git a/src/Events/SmsMessageSending.php b/src/Events/SmsMessageSending.php index 11a6d13..e98daa5 100644 --- a/src/Events/SmsMessageSending.php +++ b/src/Events/SmsMessageSending.php @@ -1,13 +1,7 @@ getCode()); $this->appendStack($throwable); } diff --git a/src/PendingSms.php b/src/PendingSms.php index e28ff51..a2d9b19 100644 --- a/src/PendingSms.php +++ b/src/PendingSms.php @@ -8,31 +8,37 @@ declare(strict_types=1); * @contact eric@zhu.email * @license https://github.com/hyperf-ext/sms/blob/master/LICENSE */ + namespace Zyimm\Sms; use Hyperf\Utils\ApplicationContext; -use Zyimm\Sms\Contract\HasMobileNumber; +use HyperfExt\Contract\HasMobileNumber; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; +use Zyimm\Sms\Contracts\MobileNumberInterface; +use Zyimm\Sms\Contracts\SenderInterface; use Zyimm\Sms\Contracts\SmsableInterface; use Zyimm\Sms\Contracts\SmsManagerInterface; +use Zyimm\Sms\Exceptions\InvalidMobileNumberException; class PendingSms { /** * The "to" recipient of the message. * - * @var \Zyimm\Sms\Contracts\MobileNumberInterface + * @var MobileNumberInterface */ - protected $to; + protected MobileNumberInterface $to; /** - * @var \Zyimm\Sms\Contracts\SmsManagerInterface + * @var SmsManagerInterface */ - protected $manger; + protected SmsManagerInterface $manger; /** - * @var \Zyimm\Sms\Contracts\SenderInterface + * @var SenderInterface */ - protected $sender; + protected SenderInterface $sender; public function __construct(SmsManagerInterface $manger) { @@ -42,13 +48,13 @@ class PendingSms /** * Set the recipients of the message. * - * @param \Zyimm\Sms\Contract\HasMobileNumber|string $number - * @param null|int|string $defaultRegion + * @param HasMobileNumber|string $number + * @param null|int|string $defaultRegion * - * @throws \Zyimm\Sms\Exceptions\InvalidMobileNumberException * @return $this + * @throws InvalidMobileNumberException */ - public function to($number, $defaultRegion = null) + public function to($number, $defaultRegion = null): PendingSms { $number = $number instanceof HasMobileNumber ? $number->getMobileNumber() : $number; @@ -60,9 +66,12 @@ class PendingSms /** * Set the sender of the SMS message. * + * @param string $name * @return $this + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ - public function sender(string $name) + public function sender(string $name): PendingSms { $this->sender = ApplicationContext::getContainer()->get(SmsManagerInterface::class)->get($name); @@ -77,6 +86,18 @@ class PendingSms return $this->manger->sendNow($this->fill($smsable)); } + /** + * Populate the SMS message with the addresses. + */ + protected function fill(SmsableInterface $smsable): SmsableInterface + { + $smsable->to($this->to); + if ($this->sender) { + $smsable->sender($this->sender->getName()); + } + return $smsable; + } + /** * Send a new SMS message instance. * @@ -102,16 +123,4 @@ class PendingSms { return $this->manger->later($this->fill($smsable), $delay, $queue); } - - /** - * Populate the SMS message with the addresses. - */ - protected function fill(SmsableInterface $smsable): SmsableInterface - { - $smsable->to($this->to); - if ($this->sender) { - $smsable->sender($this->sender->getName()); - } - return $smsable; - } } diff --git a/src/QueuedSmsableJob.php b/src/QueuedSmsableJob.php index 3addeca..a324b4f 100644 --- a/src/QueuedSmsableJob.php +++ b/src/QueuedSmsableJob.php @@ -16,9 +16,9 @@ use Zyimm\Sms\Contracts\SmsableInterface; class QueuedSmsableJob extends Job { /** - * @var \Zyimm\Sms\Contracts\SmsableInterface + * @var SmsableInterface */ - public $smsable; + public SmsableInterface $smsable; public function __construct(SmsableInterface $smsable) {