You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
payment/app/Factory/SmsSenderFactory.php

38 lines
880 B
PHP

<?php
declare(strict_types=1);
namespace App\Factory;
use App\Helper\SmsSender\JhSmsSender;
use App\Helper\SmsSender\XgSmsSender;
use App\Helper\SmsSender\ZwSmsSender;
use Psr\Container\ContainerInterface;
use App\Model\Tool;
class SmsSenderFactory
{
protected $senders = [
'sms_set' => XgSmsSender::class,
'zhongwang' => ZwSmsSender::class,
'juhedata' => JhSmsSender::class,
];
public function __invoke(ContainerInterface $container)
{
$tool = Tool::getActiveByGroup('sms');
if (!$tool) {
return null;
}
$senderClass = $this->getSenderClass($tool);
if ($senderClass) {
return make($senderClass, compact('tool'));
}
return null;
}
protected function getSenderClass(Tool $tool)
{
return $this->senders[$tool->name] ?? null;
}
}