vendor/symfony/framework-bundle/Controller/RedirectController.php line 109

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\Controller;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpKernel\Exception\HttpException;
  15. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  16. /**
  17.  * Redirects a request to another URL.
  18.  *
  19.  * @author Fabien Potencier <fabien@symfony.com>
  20.  *
  21.  * @final
  22.  */
  23. class RedirectController
  24. {
  25.     private $router;
  26.     private $httpPort;
  27.     private $httpsPort;
  28.     public function __construct(UrlGeneratorInterface $router nullint $httpPort nullint $httpsPort null)
  29.     {
  30.         $this->router $router;
  31.         $this->httpPort $httpPort;
  32.         $this->httpsPort $httpsPort;
  33.     }
  34.     /**
  35.      * Redirects to another route with the given name.
  36.      *
  37.      * The response status code is 302 if the permanent parameter is false (default),
  38.      * and 301 if the redirection is permanent.
  39.      *
  40.      * In case the route name is empty, the status code will be 404 when permanent is false
  41.      * and 410 otherwise.
  42.      *
  43.      * @param string     $route             The route name to redirect to
  44.      * @param bool       $permanent         Whether the redirection is permanent
  45.      * @param bool|array $ignoreAttributes  Whether to ignore attributes or an array of attributes to ignore
  46.      * @param bool       $keepRequestMethod Whether redirect action should keep HTTP request method
  47.      *
  48.      * @throws HttpException In case the route name is empty
  49.      */
  50.     public function redirectAction(Request $requeststring $routebool $permanent false$ignoreAttributes falsebool $keepRequestMethod falsebool $keepQueryParams false): Response
  51.     {
  52.         if ('' == $route) {
  53.             throw new HttpException($permanent 410 404);
  54.         }
  55.         $attributes = [];
  56.         if (false === $ignoreAttributes || \is_array($ignoreAttributes)) {
  57.             $attributes $request->attributes->get('_route_params');
  58.             if ($keepQueryParams) {
  59.                 if ($query $request->server->get('QUERY_STRING')) {
  60.                     $query self::parseQuery($query);
  61.                 } else {
  62.                     $query $request->query->all();
  63.                 }
  64.                 $attributes array_merge($query$attributes);
  65.             }
  66.             unset($attributes['route'], $attributes['permanent'], $attributes['ignoreAttributes'], $attributes['keepRequestMethod'], $attributes['keepQueryParams']);
  67.             if ($ignoreAttributes) {
  68.                 $attributes array_diff_key($attributesarray_flip($ignoreAttributes));
  69.             }
  70.         }
  71.         if ($keepRequestMethod) {
  72.             $statusCode $permanent 308 307;
  73.         } else {
  74.             $statusCode $permanent 301 302;
  75.         }
  76.         return new RedirectResponse($this->router->generate($route$attributesUrlGeneratorInterface::ABSOLUTE_URL), $statusCode);
  77.     }
  78.     /**
  79.      * Redirects to a URL.
  80.      *
  81.      * The response status code is 302 if the permanent parameter is false (default),
  82.      * and 301 if the redirection is permanent.
  83.      *
  84.      * In case the path is empty, the status code will be 404 when permanent is false
  85.      * and 410 otherwise.
  86.      *
  87.      * @param string      $path              The absolute path or URL to redirect to
  88.      * @param bool        $permanent         Whether the redirect is permanent or not
  89.      * @param string|null $scheme            The URL scheme (null to keep the current one)
  90.      * @param int|null    $httpPort          The HTTP port (null to keep the current one for the same scheme or the default configured port)
  91.      * @param int|null    $httpsPort         The HTTPS port (null to keep the current one for the same scheme or the default configured port)
  92.      * @param bool        $keepRequestMethod Whether redirect action should keep HTTP request method
  93.      *
  94.      * @throws HttpException In case the path is empty
  95.      */
  96.     public function urlRedirectAction(Request $requeststring $pathbool $permanent falsestring $scheme nullint $httpPort nullint $httpsPort nullbool $keepRequestMethod false): Response
  97.     {
  98.         if ('' == $path) {
  99.             throw new HttpException($permanent 410 404);
  100.         }
  101.         if ($keepRequestMethod) {
  102.             $statusCode $permanent 308 307;
  103.         } else {
  104.             $statusCode $permanent 301 302;
  105.         }
  106.         // redirect if the path is a full URL
  107.         if (parse_url($path, \PHP_URL_SCHEME)) {
  108.             return new RedirectResponse($path$statusCode);
  109.         }
  110.         if (null === $scheme) {
  111.             $scheme $request->getScheme();
  112.         }
  113.         if ($qs $request->server->get('QUERY_STRING') ?: $request->getQueryString()) {
  114.             if (!str_contains($path'?')) {
  115.                 $qs '?'.$qs;
  116.             } else {
  117.                 $qs '&'.$qs;
  118.             }
  119.         }
  120.         $port '';
  121.         if ('http' === $scheme) {
  122.             if (null === $httpPort) {
  123.                 if ('http' === $request->getScheme()) {
  124.                     $httpPort $request->getPort();
  125.                 } else {
  126.                     $httpPort $this->httpPort;
  127.                 }
  128.             }
  129.             if (null !== $httpPort && 80 != $httpPort) {
  130.                 $port ":$httpPort";
  131.             }
  132.         } elseif ('https' === $scheme) {
  133.             if (null === $httpsPort) {
  134.                 if ('https' === $request->getScheme()) {
  135.                     $httpsPort $request->getPort();
  136.                 } else {
  137.                     $httpsPort $this->httpsPort;
  138.                 }
  139.             }
  140.             if (null !== $httpsPort && 443 != $httpsPort) {
  141.                 $port ":$httpsPort";
  142.             }
  143.         }
  144.         $url $scheme.'://'.$request->getHost().$port.$request->getBaseUrl().$path.$qs;
  145.         return new RedirectResponse($url$statusCode);
  146.     }
  147.     public function __invoke(Request $request): Response
  148.     {
  149.         $p $request->attributes->get('_route_params', []);
  150.         if (\array_key_exists('route'$p)) {
  151.             if (\array_key_exists('path'$p)) {
  152.                 throw new \RuntimeException(sprintf('Ambiguous redirection settings, use the "path" or "route" parameter, not both: "%s" and "%s" found respectively in "%s" routing configuration.'$p['path'], $p['route'], $request->attributes->get('_route')));
  153.             }
  154.             return $this->redirectAction($request$p['route'], $p['permanent'] ?? false$p['ignoreAttributes'] ?? false$p['keepRequestMethod'] ?? false$p['keepQueryParams'] ?? false);
  155.         }
  156.         if (\array_key_exists('path'$p)) {
  157.             return $this->urlRedirectAction($request$p['path'], $p['permanent'] ?? false$p['scheme'] ?? null$p['httpPort'] ?? null$p['httpsPort'] ?? null$p['keepRequestMethod'] ?? false);
  158.         }
  159.         throw new \RuntimeException(sprintf('The parameter "path" or "route" is required to configure the redirect action in "%s" routing configuration.'$request->attributes->get('_route')));
  160.     }
  161.     private static function parseQuery(string $query)
  162.     {
  163.         $q = [];
  164.         foreach (explode('&'$query) as $v) {
  165.             if (false !== $i strpos($v"\0")) {
  166.                 $v substr($v0$i);
  167.             }
  168.             if (false === $i strpos($v'=')) {
  169.                 $k urldecode($v);
  170.                 $v '';
  171.             } else {
  172.                 $k urldecode(substr($v0$i));
  173.                 $v substr($v$i);
  174.             }
  175.             if (false !== $i strpos($k"\0")) {
  176.                 $k substr($k0$i);
  177.             }
  178.             $k ltrim($k' ');
  179.             if (false === $i strpos($k'[')) {
  180.                 $q[] = bin2hex($k).$v;
  181.             } else {
  182.                 $q[] = bin2hex(substr($k0$i)).rawurlencode(substr($k$i)).$v;
  183.             }
  184.         }
  185.         parse_str(implode('&'$q), $q);
  186.         $query = [];
  187.         foreach ($q as $k => $v) {
  188.             if (false !== $i strpos($k'_')) {
  189.                 $query[substr_replace($khex2bin(substr($k0$i)).'['0$i)] = $v;
  190.             } else {
  191.                 $query[hex2bin($k)] = $v;
  192.             }
  193.         }
  194.         return $query;
  195.     }
  196. }
dobrowin | betleao | moverbet | winzada 777 | supremo | casadeapostas | dobrowin | betleao | moverbet | wazamba | fezbet | betsson | lvbet | dobrowin | betsul | pixbet | bwin | betobet | dobrowin | bet7 | betcris | blaze | 888 | betano | stake | stake | esportesdasorte | betmotion | rivalry | novibet | pinnacle | cbet | dobrowin | betleao | moverbet | gogowin | jogos win | campobet | mesk bet | infinity bet | betfury | doce | bet7k | jogowin | lobo888 | iribet | leao | dobrowin | allwin | aajogo | pgwin | greenbets | brapub | moverbet | onebra | flames | brdice | brwin | poplottery | queens | winbrl | omgbet | winbra | goinbet | codbet | betleao | fuwin | allwin568 | wingdus | juntosbet | today | talon777 | brlwin | fazobetai | pinup bet | bet sport | bet esporte | mrbet | premier bet | apostebet | spicy bet | prosport bet | bet nacional | luck | jogodeouro | heads bet | marjack bet | apostaganha | gbg bet | esoccer bet | esport bet | realbet | aposte e ganhe | aviator aposta | bet vitoria | imperador bet | realsbet | bet favorita | esportenet | flames bet | pague bet | betsury | doce888 | obabet | winzada | globalbet | bet77 | lottoland | 7gamesbet | dicasbet | esportivabet | tvbet | sportbet | misterjackbet | esportebet | nacionalbet | simplesbet | betestrela | batbet | Pk55 | Bet61 | Upsports Bet | roleta online | roleta | poker online | poker | blackjack online | bingo | 12bet | 33win | bet168 | bk8 | bong88 | bong99 | fcb8 | hb88 | hotlive | ibet888 | k8 | kubet77 | kubet | lode88 | mig8 | nbet | onebox63 | oxbet | s666 | sbobet | suncity | vwin | w88 | win2888 | zbet | xoso66 | zowin | sun | top88 | vnloto | 11bet | bet69 | 8xbet | Ceará | Paysandu | Juventude | Bahia | Sport | Cuiabá | Coritiba | Criciúma | Vitória | Fortaleza | Corinthians | São Paulo | Vasco | Grêmio | Fluminense | Cruzeiro | Botafogo | Flamengo | bingo slots | slots slots | hacker do slot | pg slot demo | slot win | pg slot soft | arne slot | riqueza slots | slots 777 | pg slot | 777 slot game | slot pg soft | hacker slot | 777 slots | slot-pg-soft | fortune ox demo grátis | demo fortune ox | fortune mouse demo | fortune ox demo | jogo fortune tiger | fortune tiger grátis | fortune tiger baixar | fortune tiger demo grátis | fortune tiger demo | fortune tiger 777 | 580bet | bet 7k | leao | luck 2 | john bet | 7755 bet | cbet | bet7 | pk55 | 8800 bet | doce | bet 4 | f12bet | bet7 | ggbet | bet77 | mrbet | bet61 | tvbet | pgwin | today | fuwin | brwin | bet7k | tv bet | allwin | stake | bwin 789 | lvbet | blaze | dj bet | umbet | b1bet | 20bet | bk bet | h2bet | 7kbet | fbbet | 9d bet | 9k bet | 73 bet | ktobet | 74 bet | betpix | betvip | batbet | onabet | f12bet | codbet | winbra | b2xbet | obabet | brlwin | onebra | winbrl | omgbet | queens | brdice | brapub | flames | betano | aajogo | iribet | pixbet | betsul | fezbet | curso beta | betway | bkbet | peixe beta | bet365 | pixbet | 4 play bet | 365bet | brxbet | 939 bet | seubet | cnc bet | gbg bet | 522bet | brl bet | pagbet | jonbet | jqk bet | 166bet | abc bet | bggbet | obabet | 136bet | mmabet | win bet | ir6 bet | 667bet | qqq bet | 193 bet | 3ss bet | 317 bet | kkk bet | 585 bet | 569 bet | vai bet | aaa bet | 969 bet | z11 bet | kw bet | 26 bet | mj bet | betio | 01 bet | ut bet | 9y bet | bet70 | f9 bet | hw bet | kg bet | 5e bet | bet br | hr bet | br bet | 75 bet | 03 bet | 6z bet | 6r bet | v6 bet | 78 bet | bt bet | 80 bet | 8g bet | 72 bet | xp bet | f12 bet | p9 bet | 5 bet | 4 bet | bet 4 | r7 bet | um bet | 29 bet | 5s bet | ck bet | pg bet | ea bet | 23 bet | bl bet | 3l bet | 2a bet | p7 bet | 888 bet | 707 bet | 361 bet | bet29 | 700 bet | 161 bet | bet777 | up bet | 58 bet | nn bet | 67 bet | 22 bet | 9g bet | 1x bet | bet10 | 70 bet | 2h bet | 9r bet | 16 bet | 81 bet | 7 bet | 5u bet | 6k bet | mg bet | b1 bet | 5h bet | je- bet | joya | hopa | nomini | ls bet | 1xbit | platin | ice bet | rant | bet us | bet go | 31 bet | slingo | flush | ice36 | weiss | bet9 | rabona | i bet | starda | dreams | bongo | snatch | 10 bet | daddy | metal | zep bet | drip | gama | drake | verde | shazam | wish | thor | exclusive | sol | highway | 500 casino | jazz | howl | supernova | sherbet | fresh | daddy | jet | wish | eclipse | inplay | drip | marvel | stake | scorpion | luxebet | drake | thor | puma | winzir | loki | shazam | rivalry | f1 casino | xgbet | sushi | bk8 | art casino | manga | pgasia | gemini | bingoplus | slot vip | help slot win | 8k8 slot | tadhana slot | jili slot | 55bmw slot | vip slot | nn777 slot | jili slot 777 | tg777 slot | w500 slot | phfun slot | bmw55 slot | sg777 slot | wj slot | slot free 100 | lucky cola slot | cc6 slot | taya777 slot | ph444 slot | slot games | fb777 slot | okebet slot | help slot | tg77 slot | phwin slot | vvjl slot | fc777 slot | slot vin | yy777 slot | define slot | define slot | inplay | 99bet | 60win | melbet | jollibet | jili slot | rich711 | tayabet | phl63 | unobet | 63jili | mwplay888 | gold99 | jolibet | ubet95 | nice88 | jili777 | nn777 | phlove | jiliko | 55bmw | phoenix game | 8k8 | cgebet | 7up gaming | diamond game | hellowin | win88 | big win | kabibe game | sabong bet | phcity | colorplay | tongits go | slotsgo | spinph | go perya | casino frenzy | aurora game | escala gaming | winning plus | bingo plus | ph dream | 747 live | niceph | lucky cola | pera play