Client
1 week ago
Concerns
1 month ago
JsonResponse.php
1 month ago
RedirectResponse.php
1 week ago
Request.php
1 week ago
Response.php
1 month ago
RedirectResponse.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Redirect response for site route controllers. |
| 5 | * |
| 6 | * @package Framework |
| 7 | * @subpackage Http |
| 8 | * @since 1.0.0 |
| 9 | */ |
| 10 | namespace Kirki\Framework\Http; |
| 11 | |
| 12 | \defined('ABSPATH') || exit; |
| 13 | class RedirectResponse |
| 14 | { |
| 15 | /** |
| 16 | * The redirect target URL. |
| 17 | * |
| 18 | * @var string |
| 19 | * |
| 20 | * @since 1.0.0 |
| 21 | */ |
| 22 | protected $url; |
| 23 | /** |
| 24 | * The HTTP redirect status code. |
| 25 | * |
| 26 | * @var int |
| 27 | * |
| 28 | * @since 1.0.0 |
| 29 | */ |
| 30 | protected $status; |
| 31 | /** |
| 32 | * Create a new RedirectResponse instance. |
| 33 | * |
| 34 | * @param string $url The redirect target URL. |
| 35 | * @param int $status The HTTP status code. |
| 36 | * |
| 37 | * @return void |
| 38 | * |
| 39 | * @since 1.0.0 |
| 40 | */ |
| 41 | public function __construct(string $url, int $status = 302) |
| 42 | { |
| 43 | $this->url = $url; |
| 44 | $this->status = $status; |
| 45 | } |
| 46 | /** |
| 47 | * Get the redirect URL. |
| 48 | * |
| 49 | * @return string |
| 50 | * |
| 51 | * @since 1.0.0 |
| 52 | */ |
| 53 | public function get_url() |
| 54 | { |
| 55 | return $this->url; |
| 56 | } |
| 57 | /** |
| 58 | * Get the HTTP status code. |
| 59 | * |
| 60 | * @return int |
| 61 | * |
| 62 | * @since 1.0.0 |
| 63 | */ |
| 64 | public function get_status() |
| 65 | { |
| 66 | return $this->status; |
| 67 | } |
| 68 | /** |
| 69 | * Send the redirect and terminate the request. |
| 70 | * |
| 71 | * @return void |
| 72 | * |
| 73 | * @since 1.0.0 |
| 74 | */ |
| 75 | public function send() |
| 76 | { |
| 77 | wp_safe_redirect($this->url, $this->status); |
| 78 | exit; |
| 79 | } |
| 80 | } |
| 81 |