vendor/php-flasher/flasher-symfony/Http/Request.php line 66

  1. <?php
  2. /*
  3.  * This file is part of the PHPFlasher package.
  4.  * (c) Younes KHOUBZA <younes.khoubza@gmail.com>
  5.  */
  6. namespace Flasher\Symfony\Http;
  7. use Flasher\Prime\Http\RequestInterface;
  8. use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
  9. use Symfony\Component\HttpFoundation\Session\Session;
  10. final class Request implements RequestInterface
  11. {
  12.     /**
  13.      * @var SymfonyRequest
  14.      */
  15.     private $request;
  16.     public function __construct(SymfonyRequest $request)
  17.     {
  18.         $this->request $request;
  19.     }
  20.     /**
  21.      * {@inheritDoc}
  22.      */
  23.     public function isXmlHttpRequest()
  24.     {
  25.         return $this->request->isXmlHttpRequest();
  26.     }
  27.     /**
  28.      * {@inheritDoc}
  29.      */
  30.     public function isHtmlRequestFormat()
  31.     {
  32.         return 'html' === $this->request->getRequestFormat();
  33.     }
  34.     /**
  35.      * {@inheritDoc}
  36.      */
  37.     public function hasSession()
  38.     {
  39.         return $this->request->hasSession();
  40.     }
  41.     /**
  42.      * {@inheritDoc}
  43.      */
  44.     public function hasType($type)
  45.     {
  46.         if (!$this->hasSession()) {
  47.             return false;
  48.         }
  49.         $session $this->request->getSession();
  50.         if (!$session->isStarted()) {
  51.             return false;
  52.         }
  53.         /** @var Session $session */
  54.         $session $this->request->getSession();
  55.         $flashBag $session->getFlashBag();
  56.         return $flashBag->has($type);
  57.     }
  58.     /**
  59.      * {@inheritDoc}
  60.      */
  61.     public function getType($type)
  62.     {
  63.         /** @var Session $session */
  64.         $session $this->request->getSession();
  65.         $flashBag $session->getFlashBag();
  66.         return $flashBag->get($type);
  67.     }
  68.     /**
  69.      * {@inheritDoc}
  70.      */
  71.     public function forgetType($type)
  72.     {
  73.         $this->getType($type);
  74.     }
  75. }