You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1008 B
44 lines
1008 B
<?php
|
|
|
|
namespace IQBall\Core\Http;
|
|
|
|
class HttpResponse {
|
|
/**
|
|
* @var array<string, string>
|
|
*/
|
|
private array $headers;
|
|
private int $code;
|
|
|
|
/**
|
|
* @param int $code
|
|
* @param array<string, string> $headers
|
|
*/
|
|
public function __construct(int $code, array $headers) {
|
|
$this->code = $code;
|
|
$this->headers = $headers;
|
|
}
|
|
|
|
public function getCode(): int {
|
|
return $this->code;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function getHeaders(): array {
|
|
return $this->headers;
|
|
}
|
|
|
|
public static function fromCode(int $code): HttpResponse {
|
|
return new HttpResponse($code, []);
|
|
}
|
|
|
|
public static function redirect(string $url, int $code = HttpCodes::FOUND): HttpResponse {
|
|
if ($code < 300 || $code >= 400) {
|
|
throw new \InvalidArgumentException("given code is not a redirection http code");
|
|
}
|
|
return new HttpResponse($code, ["Location" => $url]);
|
|
}
|
|
|
|
}
|