MyPriority.php 775 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace App\Module\Sms\Strategy;
  3. use Overtrue\EasySms\Contracts\StrategyInterface;
  4. /**
  5. * 自定义短信发送策略
  6. * 优先使用数据库网关
  7. */
  8. class MyPriority implements StrategyInterface
  9. {
  10. /**
  11. * 应用策略
  12. *
  13. * @param array $gateways 可用的网关列表
  14. * @return array 排序后的网关列表
  15. */
  16. public function apply(array $gateways): array
  17. {
  18. // 查找 mygateway 在数组中的位置
  19. $index = array_search('mygateway', $gateways);
  20. // 如果找到 mygateway,则将其作为唯一的网关返回
  21. if ($index !== false) {
  22. return [$gateways[$index]];
  23. }
  24. // 如果没有找到 mygateway,则返回原始网关列表
  25. return $gateways;
  26. }
  27. }