-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.0.3 Added RedirectResponse::class.
- Loading branch information
1 parent
8ebb91d
commit 8ad1763
Showing
12 changed files
with
91 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* RedirectResponse.php | ||
* | ||
* This file is part of HTTP. | ||
* | ||
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr> | ||
* @copyright Copyright © 2022 Muhammet ŞAFAK | ||
* @license ./LICENSE MIT | ||
* @version 1.0.3 | ||
* @link https://www.muhammetsafak.com.tr | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace InitPHP\HTTP; | ||
|
||
use Psr\Http\Message\StreamInterface; | ||
use Psr\Http\Message\UriInterface; | ||
|
||
use function is_string; | ||
|
||
/** | ||
* @since 1.0.2 | ||
*/ | ||
class RedirectResponse extends Response | ||
{ | ||
/** | ||
* @param string|UriInterface $url | ||
* @param int $status | ||
* @param int $second | ||
*/ | ||
public function __construct($url, int $status = 200, int $second = 0) | ||
{ | ||
if($url instanceof UriInterface){ | ||
$url = $url->__toString(); | ||
} | ||
if(!is_string($url)){ | ||
throw new \InvalidArgumentException('The $url parameter must be an UriInterface or string.'); | ||
} | ||
if($second < 1){ | ||
$headers = [ | ||
'Location' => $url, | ||
]; | ||
}else{ | ||
$headers = [ | ||
'Refresh' => $second . '; url=' . $url, | ||
]; | ||
} | ||
parent::__construct($status, $headers, new Stream('', null), '1.1'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters