[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
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 http://tools.ietf.org/html/rfc2616#section-10.3 34 */ 35 public function __construct($url, $status = 302, $headers = array()) 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 46 /** 47 * Factory method for chainability. 48 * 49 * @param string $url The url to redirect to 50 * @param int $status The response status code 51 * @param array $headers An array of response headers 52 * 53 * @return static 54 */ 55 public static function create($url = '', $status = 302, $headers = array()) 56 { 57 return new static($url, $status, $headers); 58 } 59 60 /** 61 * Returns the target URL. 62 * 63 * @return string target URL 64 */ 65 public function getTargetUrl() 66 { 67 return $this->targetUrl; 68 } 69 70 /** 71 * Sets the redirect target of this response. 72 * 73 * @param string $url The URL to redirect to 74 * 75 * @return $this 76 * 77 * @throws \InvalidArgumentException 78 */ 79 public function setTargetUrl($url) 80 { 81 if (empty($url)) { 82 throw new \InvalidArgumentException('Cannot redirect to an empty URL.'); 83 } 84 85 $this->targetUrl = $url; 86 87 $this->setContent( 88 sprintf('<!DOCTYPE html> 89 <html> 90 <head> 91 <meta charset="UTF-8" /> 92 <meta http-equiv="refresh" content="0;url=%1$s" /> 93 94 <title>Redirecting to %1$s</title> 95 </head> 96 <body> 97 Redirecting to <a href="%1$s">%1$s</a>. 98 </body> 99 </html>', htmlspecialchars($url, ENT_QUOTES, 'UTF-8'))); 100 101 $this->headers->set('Location', $url); 102 103 return $this; 104 } 105 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |