优化
This commit is contained in:
parent
c6dab6b2a5
commit
aeb3d5a743
|
@ -451,7 +451,7 @@ Sms::to($request->user())
|
||||||
如果你希望你的短信类始终使用队列,您可以给短信消息类实现 `Zyimm\Contract\ShouldQueue` 接口,现在即使你调用了 `send` 方法,短信依旧使用队列的方式发送。另外,如果需要将短信推送到指定队列,可以设置在短信消息类中设置 `queue` 属性。
|
如果你希望你的短信类始终使用队列,您可以给短信消息类实现 `Zyimm\Contract\ShouldQueue` 接口,现在即使你调用了 `send` 方法,短信依旧使用队列的方式发送。另外,如果需要将短信推送到指定队列,可以设置在短信消息类中设置 `queue` 属性。
|
||||||
|
|
||||||
```php
|
```php
|
||||||
use Zyimm\Contract\ShouldQueue;
|
use HyperfExt\Contract\ShouldQueue;
|
||||||
use zyimm\Sms\Smsable;
|
use zyimm\Sms\Smsable;
|
||||||
|
|
||||||
class VerificationCode extends Smsable implements ShouldQueue
|
class VerificationCode extends Smsable implements ShouldQueue
|
||||||
|
|
|
@ -10,7 +10,7 @@ declare(strict_types=1);
|
||||||
*/
|
*/
|
||||||
namespace %NAMESPACE%;
|
namespace %NAMESPACE%;
|
||||||
|
|
||||||
use Zyimm\Sms\Contract\ShouldQueue;
|
use HyperfExt\Contract\ShouldQueue;;
|
||||||
use Zyimm\Sms\Contracts\SenderInterface;
|
use Zyimm\Sms\Contracts\SenderInterface;
|
||||||
use Zyimm\Sms\Smsable;
|
use Zyimm\Sms\Smsable;
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
/**
|
|
||||||
* This file is part of hyperf-ext/sms.
|
|
||||||
*
|
|
||||||
* @link https://github.com/hyperf-ext/sms
|
|
||||||
* @contact eric@zhu.email
|
|
||||||
* @license https://github.com/hyperf-ext/sms/blob/master/LICENSE
|
|
||||||
*/
|
|
||||||
namespace Zyimm\Sms\Exceptions;
|
namespace Zyimm\Sms\Exceptions;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class InvalidMobileNumberException extends InvalidArgumentException
|
class InvalidMobileNumberException extends InvalidArgumentException
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
14
src/Sms.php
14
src/Sms.php
|
@ -12,6 +12,8 @@ namespace Zyimm\Sms;
|
||||||
|
|
||||||
use Hyperf\Utils\ApplicationContext;
|
use Hyperf\Utils\ApplicationContext;
|
||||||
use HyperfExt\Contract\HasMailAddress;
|
use HyperfExt\Contract\HasMailAddress;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Zyimm\Sms\Contracts\SmsManagerInterface;
|
use Zyimm\Sms\Contracts\SmsManagerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,6 +21,10 @@ use Zyimm\Sms\Contracts\SmsManagerInterface;
|
||||||
*/
|
*/
|
||||||
class Sms
|
class Sms
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
public static function __callStatic(string $method, array $args)
|
public static function __callStatic(string $method, array $args)
|
||||||
{
|
{
|
||||||
$instance = static::getManager();
|
$instance = static::getManager();
|
||||||
|
@ -26,11 +32,19 @@ class Sms
|
||||||
return $instance->{$method}(...$args);
|
return $instance->{$method}(...$args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
public static function sender(string $name): PendingSms
|
public static function sender(string $name): PendingSms
|
||||||
{
|
{
|
||||||
return (new PendingSms(static::getManager()))->sender($name);
|
return (new PendingSms(static::getManager()))->sender($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
protected static function getManager()
|
protected static function getManager()
|
||||||
{
|
{
|
||||||
return ApplicationContext::getContainer()->get(SmsManagerInterface::class);
|
return ApplicationContext::getContainer()->get(SmsManagerInterface::class);
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
/**
|
|
||||||
* This file is part of hyperf-ext/sms.
|
|
||||||
*
|
|
||||||
* @link https://github.com/hyperf-ext/sms
|
|
||||||
* @contact eric@zhu.email
|
|
||||||
* @license https://github.com/hyperf-ext/sms/blob/master/LICENSE
|
|
||||||
*/
|
|
||||||
namespace Zyimm\Sms;
|
namespace Zyimm\Sms;
|
||||||
|
|
||||||
use Hyperf\Contract\ConfigInterface;
|
use Hyperf\Contract\ConfigInterface;
|
||||||
use Zyimm\Sms\Contract\ShouldQueue;
|
use HyperfExt\Contract\HasMobileNumber;
|
||||||
|
use HyperfExt\Contract\ShouldQueue;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Zyimm\Sms\Contracts\SenderInterface;
|
use Zyimm\Sms\Contracts\SenderInterface;
|
||||||
use Zyimm\Sms\Contracts\SmsableInterface;
|
use Zyimm\Sms\Contracts\SmsableInterface;
|
||||||
use Zyimm\Sms\Contracts\SmsManagerInterface;
|
use Zyimm\Sms\Contracts\SmsManagerInterface;
|
||||||
|
use Zyimm\Sms\Exceptions\InvalidMobileNumberException;
|
||||||
use Zyimm\Sms\Exceptions\StrategicallySendMessageException;
|
use Zyimm\Sms\Exceptions\StrategicallySendMessageException;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use LogicException;
|
use LogicException;
|
||||||
|
@ -26,16 +24,16 @@ class SmsManager implements SmsManagerInterface
|
||||||
/**
|
/**
|
||||||
* The container instance.
|
* The container instance.
|
||||||
*
|
*
|
||||||
* @var \Psr\Container\ContainerInterface
|
* @var ContainerInterface
|
||||||
*/
|
*/
|
||||||
protected $container;
|
protected ContainerInterface $container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The array of resolved senders.
|
* The array of resolved senders.
|
||||||
*
|
*
|
||||||
* @var \Zyimm\Sms\Contracts\SenderInterface[]
|
* @var SenderInterface[]
|
||||||
*/
|
*/
|
||||||
protected $senders = [];
|
protected array $senders = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The config instance.
|
* The config instance.
|
||||||
|
@ -46,6 +44,10 @@ class SmsManager implements SmsManagerInterface
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Mail manager instance.
|
* Create a new Mail manager instance.
|
||||||
|
*
|
||||||
|
* @param ContainerInterface $container
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
|
@ -81,9 +83,18 @@ class SmsManager implements SmsManagerInterface
|
||||||
throw $exception;
|
throw $exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send
|
||||||
|
*
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
public function send(SmsableInterface $smsable)
|
public function send(SmsableInterface $smsable)
|
||||||
{
|
{
|
||||||
if ($smsable instanceof ShouldQueue) {
|
if ($smsable instanceof ShouldQueue) {
|
||||||
|
/**
|
||||||
|
* @var Smsable|ShouldQueue $smsable
|
||||||
|
*/
|
||||||
return $smsable->queue();
|
return $smsable->queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,16 +112,22 @@ class SmsManager implements SmsManagerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Zyimm\Sms\Contract\HasMobileNumber|string $number
|
* @param HasMobileNumber|string $number
|
||||||
* @param null|int|string $defaultRegion
|
* @param null|int|string $defaultRegion
|
||||||
*
|
*
|
||||||
* @throws \Zyimm\Sms\Exceptions\InvalidMobileNumberException
|
* @throws InvalidMobileNumberException
|
||||||
*/
|
*/
|
||||||
public function to($number, $defaultRegion = null): PendingSms
|
public function to($number, $defaultRegion = null): PendingSms
|
||||||
{
|
{
|
||||||
return (new PendingSms($this))->to($number, $defaultRegion);
|
return (new PendingSms($this))->to($number, $defaultRegion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* applyStrategy
|
||||||
|
*
|
||||||
|
* @param SmsableInterface $smsable
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function applyStrategy(SmsableInterface $smsable): array
|
protected function applyStrategy(SmsableInterface $smsable): array
|
||||||
{
|
{
|
||||||
$senders = (is_array($smsable->senders) && count($smsable->senders) > 0)
|
$senders = (is_array($smsable->senders) && count($smsable->senders) > 0)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user