Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
RedirectResponse.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\HttpFoundation;
013
014 /**
015 * RedirectResponse represents an HTTP response doing a redirect.
016 *
017 * @author Fabien Potencier <fabien@symfony.com>
018 */
019 class RedirectResponse extends Response
020 {
021 protected $targetUrl;
022
023 /**
024 * Creates a redirect response so that it conforms to the rules defined for a redirect status code.
025 *
026 * @param string $url The URL to redirect to. The URL should be a full URL, with schema etc.,
027 * but practically every browser redirects on paths only as well
028 * @param int $status The status code (302 by default)
029 * @param array $headers The headers (Location is always set to the given URL)
030 *
031 * @throws \InvalidArgumentException
032 *
033 * @see https://tools.ietf.org/html/rfc2616#section-10.3
034 */
035 public function __construct($url, $status = 302, $headers = [])
036 {
037 parent::__construct('', $status, $headers);
038
039 $this->setTargetUrl($url);
040
041 if (!$this->isRedirect()) {
042 throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
043 }
044
045 if (301 == $status && !\array_key_exists('cache-control', array_change_key_case($headers, \CASE_LOWER))) {
046 $this->headers->remove('cache-control');
047 }
048 }
049
050 /**
051 * Factory method for chainability.
052 *
053 * @param string $url The url to redirect to
054 * @param int $status The response status code
055 * @param array $headers An array of response headers
056 *
057 * @return static
058 */
059 public static function create($url = '', $status = 302, $headers = [])
060 {
061 return new static($url, $status, $headers);
062 }
063
064 /**
065 * Returns the target URL.
066 *
067 * @return string target URL
068 */
069 public function getTargetUrl()
070 {
071 return $this->targetUrl;
072 }
073
074 /**
075 * Sets the redirect target of this response.
076 *
077 * @param string $url The URL to redirect to
078 *
079 * @return $this
080 *
081 * @throws \InvalidArgumentException
082 */
083 public function setTargetUrl($url)
084 {
085 if (empty($url)) {
086 throw new \InvalidArgumentException('Cannot redirect to an empty URL.');
087 }
088
089 $this->targetUrl = $url;
090
091 $this->setContent(
092 sprintf('<!DOCTYPE html>
093 <html>
094 <head>
095 <meta charset="UTF-8" />
096 <meta http-equiv="refresh" content="0;url=\'%1$s\'" />
097
098 <title>Redirecting to %1$s</title>
099 </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
107 return $this;
108 }
109 }
110