-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Chatter.php
55 lines (45 loc) · 1.42 KB
/
Chatter.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
<?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\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 Chatter implements ChatterInterface
{
public function __construct(
private TransportInterface $transport,
private ?MessageBusInterface $bus = null,
private ?EventDispatcherInterface $dispatcher = null,
) {
}
public function __toString(): string
{
return 'chat';
}
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);
}
$this->dispatcher?->dispatch(new MessageEvent($message, true));
$this->bus->dispatch($message);
return null;
}
}