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 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 8
BrowserChannel
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 8
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 notify
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 6
 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\HttpFoundation\RequestStack;
15use Symfony\Component\Notifier\Notification\Notification;
16use Symfony\Component\Notifier\Recipient\Recipient;
17
18/**
19 * @author Fabien Potencier <fabien@symfony.com>
20 *
21 * @experimental in 5.1
22 */
23final class BrowserChannel implements ChannelInterface
24{
25    private $stack;
26
27    public function __construct(RequestStack $stack)
28    {
29        $this->stack = $stack;
30    }
31
32    public function notify(Notification $notification, Recipient $recipient, string $transportName = null): void
33    {
34        if (null === $request = $this->stack->getCurrentRequest()) {
35            return;
36        }
37
38        $message = $notification->getSubject();
39        if ($notification->getEmoji()) {
40            $message = $notification->getEmoji().' '.$message;
41        }
42        $request->getSession()->getFlashBag()->add('notification', $message);
43    }
44
45    public function supports(Notification $notification, Recipient $recipient): bool
46    {
47        return true;
48    }
49}