vendor/symfony/notifier/Channel/BrowserChannel.php line 35

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Notifier\Channel;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\Component\Notifier\FlashMessage\DefaultFlashMessageImportanceMapper;
  13. use Symfony\Component\Notifier\FlashMessage\FlashMessageImportanceMapperInterface;
  14. use Symfony\Component\Notifier\Notification\Notification;
  15. use Symfony\Component\Notifier\Recipient\RecipientInterface;
  16. /**
  17.  * @author Fabien Potencier <fabien@symfony.com>
  18.  */
  19. final class BrowserChannel implements ChannelInterface
  20. {
  21.     private RequestStack $stack;
  22.     private FlashMessageImportanceMapperInterface $mapper;
  23.     public function __construct(RequestStack $stackFlashMessageImportanceMapperInterface $mapper = new DefaultFlashMessageImportanceMapper())
  24.     {
  25.         $this->stack $stack;
  26.         $this->mapper $mapper;
  27.     }
  28.     public function notify(Notification $notificationRecipientInterface $recipientstring $transportName null): void
  29.     {
  30.         if (null === $request $this->stack->getCurrentRequest()) {
  31.             return;
  32.         }
  33.         $message $notification->getSubject();
  34.         if ($notification->getEmoji()) {
  35.             $message $notification->getEmoji().' '.$message;
  36.         }
  37.         $request->getSession()->getFlashBag()->add($this->mapper->flashMessageTypeFromImportance($notification->getImportance()), $message);
  38.     }
  39.     public function supports(Notification $notificationRecipientInterface $recipient): bool
  40.     {
  41.         return true;
  42.     }
  43. }