This commit is contained in:
2025-07-08 11:43:04 +08:00
parent f38942f4f3
commit 8623a036ed
2 changed files with 30 additions and 0 deletions
+20
View File
@@ -8,6 +8,7 @@ use Kiri\Router\ContentType;
use Kiri\Router\StreamResponse;
use Psr\Http\Message\ResponseInterface;
class ConstrictResponse extends Message implements ResponseInterface
{
@@ -30,6 +31,25 @@ class ConstrictResponse extends Message implements ResponseInterface
}
/**
* @param string $url
* @param array $params
* @param int $statusCode
* @return static
*/
public function redirectTo(string $url, array $params = [], int $statusCode = 302): static
{
if (!empty($params)) {
$url .= '?' . http_build_query($params);
}
$this->withHeader('Location', $url);
$this->withStatus($statusCode);
return $this;
}
/**
* @param ContentType $contentType
* @return $this
+10
View File
@@ -68,6 +68,16 @@ class Response implements ResponseInterface
return $this->__call__(__FUNCTION__, $content, $statusCode);
}
/**
* @param string $url
* @param array $params
* @param int $statusCode
* @return ResponseInterface
*/
public function redirectTo(string $url, array $params = [], int $statusCode = 302): ResponseInterface
{
return $this->__call__(__FUNCTION__, $url, $params, $statusCode);
}
/**
* @param array $content