|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Leonidas\Framework\Site\Provider; |
|
4
|
|
|
|
|
5
|
|
|
use Panamax\Contracts\ServiceFactoryInterface; |
|
6
|
|
|
use Panamax\Factories\AbstractServiceFactory; |
|
7
|
|
|
use Psr\Container\ContainerInterface; |
|
8
|
|
|
use Psr\EventDispatcher\EventDispatcherInterface; |
|
9
|
|
|
use Psr\Log\LoggerInterface; |
|
10
|
|
|
use Symfony\Component\Mailer\Mailer; |
|
11
|
|
|
use Symfony\Component\Mailer\MailerInterface; |
|
12
|
|
|
use Symfony\Component\Mailer\Transport\Smtp\SmtpTransport; |
|
13
|
|
|
use Symfony\Component\Mailer\Transport\Smtp\Stream\AbstractStream; |
|
14
|
|
|
use Symfony\Component\Mailer\Transport\TransportInterface; |
|
15
|
|
|
use Symfony\Component\Messenger\MessageBusInterface; |
|
16
|
|
|
|
|
17
|
|
|
class SymfonyMailerProvider extends AbstractServiceFactory implements ServiceFactoryInterface |
|
18
|
|
|
{ |
|
19
|
|
|
public function create(ContainerInterface $container, array $args = []): MailerInterface |
|
20
|
|
|
{ |
|
21
|
|
|
return new Mailer( |
|
22
|
|
|
$this->getTransport($container, $args), |
|
23
|
|
|
$this->getMessageBus($container, $args), |
|
24
|
|
|
$this->getEventDispatcher($container, $args), |
|
25
|
|
|
); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
protected function getTransport(ContainerInterface $container, array $args = []): TransportInterface |
|
29
|
|
|
{ |
|
30
|
|
|
$service = $args['$transport'] ?? TransportInterface::class; |
|
31
|
|
|
|
|
32
|
|
|
return $container->has($service) |
|
33
|
|
|
? $container->get($service) |
|
34
|
|
|
: $this->defaultTransport($container, $args); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function defaultTransport(ContainerInterface $container, array $args): TransportInterface |
|
38
|
|
|
{ |
|
39
|
|
|
return new SmtpTransport( |
|
40
|
|
|
$this->getStream($container, $args), |
|
41
|
|
|
$this->getEventDispatcher($container, $args), |
|
42
|
|
|
$this->getLogger($container, $args) |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function getMessageBus(ContainerInterface $container, array $args = []): ?MessageBusInterface |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->fetch( |
|
49
|
|
|
$args['$message_bus'] ?? MessageBusInterface::class, |
|
50
|
|
|
$container |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
protected function getEventDispatcher(ContainerInterface $container, array $args = []): ?EventDispatcherInterface |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->fetch( |
|
57
|
|
|
$args['$event_dispatcher'] ?? EventDispatcherInterface::class, |
|
58
|
|
|
$container |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
protected function getStream(ContainerInterface $container, array $args = []): ?AbstractStream |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->fetch( |
|
65
|
|
|
$args['$stream'] ?? AbstractStream::class, |
|
66
|
|
|
$container |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
protected function getLogger(ContainerInterface $container, array $args = []): ?LoggerInterface |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->fetch( |
|
73
|
|
|
$args['$logger'] ?? LoggerInterface::class, |
|
74
|
|
|
$container |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|