| 1 | <?php |
||
| 13 | class RedirectResponse extends Response { |
||
| 14 | /** |
||
| 15 | * Current request. |
||
| 16 | * |
||
| 17 | * @var Request |
||
| 18 | */ |
||
| 19 | protected $request = null; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Constructor. |
||
| 23 | * |
||
| 24 | * @param Request $request |
||
| 25 | */ |
||
| 26 | public function __construct( Request $request ) { |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Get a response redirecting to a specific url. |
||
| 32 | * |
||
| 33 | * @param string $url |
||
| 34 | * @param integer $status |
||
| 35 | * @return ResponseInterface |
||
| 36 | */ |
||
| 37 | 2 | public function to( $url, $status = 302 ) { |
|
| 40 | |||
| 41 | /** |
||
| 42 | * Get a response redirecting back to the referrer or a fallback. |
||
| 43 | * |
||
| 44 | * @param string $fallback |
||
| 45 | * @param integer $status |
||
| 46 | * @return ResponseInterface |
||
| 47 | */ |
||
| 48 | 4 | public function back( $fallback = '', $status = 302 ) { |
|
| 61 | } |
||
| 62 | |||
| 65 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: