-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathTexter.php
63 lines (52 loc) · 1.78 KB
/
Texter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Notifier;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Notifier\Event\MessageEvent;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* @author Fabien Potencier <[email protected]>
*/
final class Texter implements TexterInterface
{
private $transport;
private $bus;
private $dispatcher;
public function __construct(TransportInterface $transport, ?MessageBusInterface $bus = null, ?EventDispatcherInterface $dispatcher = null)
{
$this->transport = $transport;
$this->bus = $bus;
$this->dispatcher = class_exists(Event::class) ? LegacyEventDispatcherProxy::decorate($dispatcher) : $dispatcher;
}
public function __toString(): string
{
return 'texter';
}
public function supports(MessageInterface $message): bool
{
return $this->transport->supports($message);
}
public function send(MessageInterface $message): ?SentMessage
{
if (null === $this->bus) {
return $this->transport->send($message);
}
if (null !== $this->dispatcher) {
$this->dispatcher->dispatch(new MessageEvent($message, true));
}
$this->bus->dispatch($message);
return null;
}
}