vendor/dachcom-digital/formbuilder/src/FormBuilderBundle/Session/FlashBagManager.php line 56

Open in your IDE?
  1. <?php
  2. namespace FormBuilderBundle\Session;
  3. use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
  4. use Symfony\Component\HttpFoundation\Session\Session;
  5. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  6. class FlashBagManager implements FlashBagManagerInterface
  7. {
  8.     protected SessionInterface $session;
  9.     public function __construct(SessionInterface $session)
  10.     {
  11.         $this->session $session;
  12.     }
  13.     public function has(string $type): bool
  14.     {
  15.         if (!$this->flashBagIsAvailable()) {
  16.             return false;
  17.         }
  18.         return $this->getFlashBag()->has($type);
  19.     }
  20.     public function add(string $typemixed $message): void
  21.     {
  22.         if (!$this->flashBagIsAvailable()) {
  23.             return;
  24.         }
  25.         $this->getFlashBag()->add($type$message);
  26.     }
  27.     public function get(string $type, array $default = []): array
  28.     {
  29.         if (!$this->flashBagIsAvailable()) {
  30.             return [];
  31.         }
  32.         return $this->getFlashBag()->get($type$default);
  33.     }
  34.     public function flashBagIsAvailable(): bool
  35.     {
  36.         return $this->session instanceof Session;
  37.     }
  38.     public function getFlashBag(): ?FlashBagInterface
  39.     {
  40.         if (!$this->session instanceof Session) {
  41.             return null;
  42.         }
  43.         return $this->session->getFlashBag();
  44.     }
  45. }