vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/RequestHelper.php line 14

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\Bundle\FrameworkBundle\Templating\Helper;
  11. @trigger_error('The '.RequestHelper::class.' class is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.'E_USER_DEPRECATED);
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. use Symfony\Component\Templating\Helper\Helper;
  14. /**
  15.  * RequestHelper provides access to the current request parameters.
  16.  *
  17.  * @author Fabien Potencier <fabien@symfony.com>
  18.  *
  19.  * @deprecated since version 4.3, to be removed in 5.0; use Twig instead.
  20.  */
  21. class RequestHelper extends Helper
  22. {
  23.     protected $requestStack;
  24.     public function __construct(RequestStack $requestStack)
  25.     {
  26.         $this->requestStack $requestStack;
  27.     }
  28.     /**
  29.      * Returns a parameter from the current request object.
  30.      *
  31.      * @param string $key     The name of the parameter
  32.      * @param string $default A default value
  33.      *
  34.      * @return mixed
  35.      *
  36.      * @see Request::get()
  37.      */
  38.     public function getParameter($key$default null)
  39.     {
  40.         return $this->getRequest()->get($key$default);
  41.     }
  42.     /**
  43.      * Returns the locale.
  44.      *
  45.      * @return string
  46.      */
  47.     public function getLocale()
  48.     {
  49.         return $this->getRequest()->getLocale();
  50.     }
  51.     private function getRequest()
  52.     {
  53.         if (!$this->requestStack->getCurrentRequest()) {
  54.             throw new \LogicException('A Request must be available.');
  55.         }
  56.         return $this->requestStack->getCurrentRequest();
  57.     }
  58.     /**
  59.      * {@inheritdoc}
  60.      */
  61.     public function getName()
  62.     {
  63.         return 'request';
  64.     }
  65. }