mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-07-02 18:14:42 +02:00
refactor: introduce http Request object (#3926)
This commit is contained in:
parent
9574c17ddc
commit
d08d13f2c8
19 changed files with 125 additions and 94 deletions
40
lib/http.php
40
lib/http.php
|
@ -166,6 +166,46 @@ final class CurlHttpClient implements HttpClient
|
|||
}
|
||||
}
|
||||
|
||||
final class Request
|
||||
{
|
||||
private array $get;
|
||||
private array $server;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function fromGlobals(): self
|
||||
{
|
||||
$self = new self();
|
||||
$self->get = $_GET;
|
||||
$self->server = $_SERVER;
|
||||
return $self;
|
||||
}
|
||||
|
||||
public static function fromCli(array $cliArgs): self
|
||||
{
|
||||
$self = new self();
|
||||
$self->get = $cliArgs;
|
||||
return $self;
|
||||
}
|
||||
|
||||
public function get(string $key, $default = null): ?string
|
||||
{
|
||||
return $this->get[$key] ?? $default;
|
||||
}
|
||||
|
||||
public function server(string $key, string $default = null): ?string
|
||||
{
|
||||
return $this->server[$key] ?? $default;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->get;
|
||||
}
|
||||
}
|
||||
|
||||
final class Response
|
||||
{
|
||||
public const STATUS_CODES = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue