PluginProbe
WPIDE – File Manager & Code Editor / 3.5.9
WPIDE – File Manager & Code Editor v3.5.9
3.5.9 3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 All 55 releases
wpide / vendor / symfony / http-foundation / RedirectResponse.php

RedirectResponse.php in WPIDE – File Manager & Code Editor 3.5.9, at vendor/symfony/http-foundation/RedirectResponse.php

111 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\HttpFoundation;
13
14 /**
15 * RedirectResponse represents an HTTP response doing a redirect.
16 *
17 * @author Fabien Potencier <fabien@symfony.com>
18 */
19 class RedirectResponse extends Response
20 {
21 protected $targetUrl;
22
23 /**
24 * Creates a redirect response so that it conforms to the rules defined for a redirect status code.
25 *
26 * @param string $url The URL to redirect to. The URL should be a full URL, with schema etc.,
27 * but practically every browser redirects on paths only as well
28 * @param int $status The status code (302 by default)
29 * @param array $headers The headers (Location is always set to the given URL)
30 *
31 * @throws \InvalidArgumentException
32 *
33 * @see https://tools.ietf.org/html/rfc2616#section-10.3
34 */
35 public function __construct(string $url, int $status = 302, array $headers = [])
36 {
37 parent::__construct('', $status, $headers);
38
39 $this->setTargetUrl($url);
40
41 if (!$this->isRedirect()) {
42 throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
43 }
44
45 if (301 == $status && !\array_key_exists('cache-control', array_change_key_case($headers, \CASE_LOWER))) {
46 $this->headers->remove('cache-control');
47 }
48 }
49
50 /**
51 * Factory method for chainability.
52 *
53 * @param string $url The URL to redirect to
54 *
55 * @return static
56 *
57 * @deprecated since Symfony 5.1, use __construct() instead.
58 */
59 public static function create($url = '', int $status = 302, array $headers = [])
60 {
61 trigger_deprecation('symfony/http-foundation', '5.1', 'The "%s()" method is deprecated, use "new %s()" instead.', __METHOD__, static::class);
62
63 return new static($url, $status, $headers);
64 }
65
66 /**
67 * Returns the target URL.
68 *
69 * @return string
70 */
71 public function getTargetUrl()
72 {
73 return $this->targetUrl;
74 }
75
76 /**
77 * Sets the redirect target of this response.
78 *
79 * @return $this
80 *
81 * @throws \InvalidArgumentException
82 */
83 public function setTargetUrl(string $url)
84 {
85 if ('' === $url) {
86 throw new \InvalidArgumentException('Cannot redirect to an empty URL.');
87 }
88
89 $this->targetUrl = $url;
90
91 $this->setContent(
92 sprintf('<!DOCTYPE html>
93 <html>
94 <head>
95 <meta charset="UTF-8" />
96 <meta http-equiv="refresh" content="0;url=\'%1$s\'" />
97
98 <title>Redirecting to %1$s</title>
99 </head>
100 <body>
101 Redirecting to <a href="%1$s">%1$s</a>.
102 </body>
103 </html>', htmlspecialchars($url, \ENT_QUOTES, 'UTF-8')));
104
105 $this->headers->set('Location', $url);
106 $this->headers->set('Content-Type', 'text/html; charset=utf-8');
107
108 return $this;
109 }
110 }
111