1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Da\Mailer\Builder; |
4
|
|
|
|
5
|
|
|
use Da\Mailer\Enum\MessageBrokerEnum; |
6
|
|
|
use Da\Mailer\Exception\UndefinedMessageBrokerException; |
7
|
|
|
use Da\Mailer\Model\MailJob; |
8
|
|
|
use Da\Mailer\Queue\Backend\Beanstalkd\BeanstalkdMailJob; |
9
|
|
|
use Da\Mailer\Queue\Backend\Pdo\PdoMailJob; |
10
|
|
|
use Da\Mailer\Queue\Backend\RabbitMq\RabbitMqJob; |
11
|
|
|
use Da\Mailer\Queue\Backend\Redis\RedisMailJob; |
12
|
|
|
use Da\Mailer\Queue\Backend\Sqs\SqsMailJob; |
13
|
|
|
|
14
|
|
|
class MailJobBuilder extends Buildable |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @param array|null $jobAttributes |
18
|
|
|
* @param string|null $broker |
19
|
|
|
* @return MailJob |
20
|
|
|
* @throws UndefinedMessageBrokerException |
21
|
|
|
*/ |
22
|
|
|
public static function make($jobAttributes = null, ?string $broker = null): MailJob |
23
|
|
|
{ |
24
|
|
|
$config = self::getConfig(); |
25
|
|
|
$messageBroker = $broker ?? $config['config']['message_broker']; |
26
|
|
|
|
27
|
|
|
switch ($messageBroker) { |
28
|
|
|
case MessageBrokerEnum::BROKER_REDIS: |
29
|
|
|
return new RedisMailJob($jobAttributes); |
|
|
|
|
30
|
|
|
case MessageBrokerEnum::BROKER_SQS: |
31
|
|
|
return new SqsMailJob($jobAttributes); |
|
|
|
|
32
|
|
|
case MessageBrokerEnum::BROKER_BEANSTALKD: |
33
|
|
|
return new BeanstalkdMailJob($jobAttributes); |
|
|
|
|
34
|
|
|
case MessageBrokerEnum::BROKER_PDO: |
35
|
|
|
return new PdoMailJob($jobAttributes); |
|
|
|
|
36
|
|
|
case MessageBrokerEnum::BROKER_RABBITMQ: |
37
|
|
|
return new RabbitMqJob($jobAttributes); |
|
|
|
|
38
|
|
|
default: |
39
|
|
|
throw new UndefinedMessageBrokerException(); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|