Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 13
ChatChannel
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 13
 notify
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 12
 supports
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
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
12namespace Symfony\Component\Notifier\Channel;
13
14use Symfony\Component\Notifier\Exception\LogicException;
15use Symfony\Component\Notifier\Message\ChatMessage;
16use Symfony\Component\Notifier\Notification\ChatNotificationInterface;
17use Symfony\Component\Notifier\Notification\Notification;
18use Symfony\Component\Notifier\Recipient\Recipient;
19
20/**
21 * @author Fabien Potencier <fabien@symfony.com>
22 *
23 * @experimental in 5.1
24 */
25class ChatChannel extends AbstractChannel
26{
27    public function notify(Notification $notification, Recipient $recipient, string $transportName = null): void
28    {
29        if (null === $transportName) {
30            throw new LogicException('A Chat notification must have a transport defined.');
31        }
32
33        $message = null;
34        if ($notification instanceof ChatNotificationInterface) {
35            $message = $notification->asChatMessage($recipient, $transportName);
36        }
37
38        if (null === $message) {
39            $message = ChatMessage::fromNotification($notification);
40        }
41
42        $message->transport($transportName);
43
44        if (null === $this->bus) {
45            $this->transport->send($message);
46        } else {
47            $this->bus->dispatch($message);
48        }
49    }
50
51    public function supports(Notification $notification, Recipient $recipient): bool
52    {
53        return true;
54    }
55}