Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 11 |
Chatter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 11 |
__construct | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
__toString | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
supports | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
send | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 6 |
1 | <?php |
2 | |
3 | /* |
4 | * This file is part of the Symfony package. |
5 | * |
6 | * (c) Fabien Potencier <fabien@symfony.com> |
7 | * |
8 | * For the full copyright and license information, please view the LICENSE |
9 | * file that was distributed with this source code. |
10 | */ |
11 | |
12 | namespace Symfony\Component\Notifier; |
13 | |
14 | use Symfony\Component\EventDispatcher\Event; |
15 | use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; |
16 | use Symfony\Component\Messenger\MessageBusInterface; |
17 | use Symfony\Component\Notifier\Event\MessageEvent; |
18 | use Symfony\Component\Notifier\Message\MessageInterface; |
19 | use Symfony\Component\Notifier\Transport\TransportInterface; |
20 | use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; |
21 | |
22 | /** |
23 | * @author Fabien Potencier <fabien@symfony.com> |
24 | * |
25 | * @experimental in 5.1 |
26 | */ |
27 | final class Chatter implements ChatterInterface |
28 | { |
29 | private $transport; |
30 | private $bus; |
31 | private $dispatcher; |
32 | |
33 | public function __construct(TransportInterface $transport, MessageBusInterface $bus = null, EventDispatcherInterface $dispatcher = null) |
34 | { |
35 | $this->transport = $transport; |
36 | $this->bus = $bus; |
37 | $this->dispatcher = class_exists(Event::class) ? LegacyEventDispatcherProxy::decorate($dispatcher) : $dispatcher; |
38 | } |
39 | |
40 | public function __toString(): string |
41 | { |
42 | return 'chat'; |
43 | } |
44 | |
45 | public function supports(MessageInterface $message): bool |
46 | { |
47 | return $this->transport->supports($message); |
48 | } |
49 | |
50 | public function send(MessageInterface $message): void |
51 | { |
52 | if (null === $this->bus) { |
53 | $this->transport->send($message); |
54 | |
55 | return; |
56 | } |
57 | |
58 | if (null !== $this->dispatcher) { |
59 | $this->dispatcher->dispatch(new MessageEvent($message, true)); |
60 | } |
61 | |
62 | $this->bus->dispatch($message); |
63 | } |
64 | } |