Overview

Namespaces

  • Composer
    • Autoload
  • Guzzle
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
        • Header
      • QueryAggregator
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Mock
    • Stream
  • Mockery
    • Adapter
      • Phpunit
    • CountValidator
    • Exception
    • Generator
      • StringManipulation
        • Pass
    • Loader
    • Matcher
  • None
  • Omnipay
    • Common
      • Exception
      • Message
    • Dummy
      • Message
    • Fatzebra
      • Message
  • PHP
  • Symfony
    • Component
      • EventDispatcher
        • Debug
        • DependencyInjection
        • Tests
          • Debug
          • DependencyInjection
      • HttpFoundation
        • File
          • Exception
          • MimeType
        • Session
          • Attribute
          • Flash
          • Storage
            • Handler
            • Proxy
        • Tests
          • File
            • MimeType
          • Session
            • Attribute
            • Flash
            • Storage
              • Handler
              • Proxy
      • Yaml
        • Exception
        • Tests

Classes

  • Symfony\Component\Yaml\Tests\A
  • Symfony\Component\Yaml\Tests\B
  • Symfony\Component\Yaml\Tests\DumperTest
  • Symfony\Component\Yaml\Tests\InlineTest
  • Symfony\Component\Yaml\Tests\ParseExceptionTest
  • Symfony\Component\Yaml\Tests\ParserTest
  • Symfony\Component\Yaml\Tests\YamlTest
  • Overview
  • Namespace
  • Function
  • Tree
  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:  * @api
 20:  */
 21: class RedirectResponse extends Response
 22: {
 23:     protected $targetUrl;
 24: 
 25:     /**
 26:      * Creates a redirect response so that it conforms to the rules defined for a redirect status code.
 27:      *
 28:      * @param string $url     The URL to redirect to
 29:      * @param int    $status  The status code (302 by default)
 30:      * @param array  $headers The headers (Location is always set to the given URL)
 31:      *
 32:      * @throws \InvalidArgumentException
 33:      *
 34:      * @see http://tools.ietf.org/html/rfc2616#section-10.3
 35:      *
 36:      * @api
 37:      */
 38:     public function __construct($url, $status = 302, $headers = array())
 39:     {
 40:         if (empty($url)) {
 41:             throw new \InvalidArgumentException('Cannot redirect to an empty URL.');
 42:         }
 43: 
 44:         parent::__construct('', $status, $headers);
 45: 
 46:         $this->setTargetUrl($url);
 47: 
 48:         if (!$this->isRedirect()) {
 49:             throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
 50:         }
 51:     }
 52: 
 53:     /**
 54:      * {@inheritdoc}
 55:      */
 56:     public static function create($url = '', $status = 302, $headers = array())
 57:     {
 58:         return new static($url, $status, $headers);
 59:     }
 60: 
 61:     /**
 62:      * Returns the target URL.
 63:      *
 64:      * @return string target URL
 65:      */
 66:     public function getTargetUrl()
 67:     {
 68:         return $this->targetUrl;
 69:     }
 70: 
 71:     /**
 72:      * Sets the redirect target of this response.
 73:      *
 74:      * @param string $url The URL to redirect to
 75:      *
 76:      * @return RedirectResponse The current response.
 77:      *
 78:      * @throws \InvalidArgumentException
 79:      */
 80:     public function setTargetUrl($url)
 81:     {
 82:         if (empty($url)) {
 83:             throw new \InvalidArgumentException('Cannot redirect to an empty URL.');
 84:         }
 85: 
 86:         $this->targetUrl = $url;
 87: 
 88:         $this->setContent(
 89:             sprintf('<!DOCTYPE html>
 90: <html>
 91:     <head>
 92:         <meta charset="UTF-8" />
 93:         <meta http-equiv="refresh" content="1;url=%1$s" />
 94: 
 95:         <title>Redirecting to %1$s</title>
 96:     </head>
 97:     <body>
 98:         Redirecting to <a href="%1$s">%1$s</a>.
 99:     </body>
100: </html>', htmlspecialchars($url, ENT_QUOTES, 'UTF-8')));
101: 
102:         $this->headers->set('Location', $url);
103: 
104:         return $this;
105:     }
106: }
107: 
Omnipay Fat Zebra / Paystream Gateway Module API Documentation API documentation generated by ApiGen