feat: token authentication (#3927)

This commit is contained in:
Dag 2024-01-25 18:20:02 +01:00 committed by GitHub
parent d08d13f2c8
commit e58c867a82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 95 additions and 138 deletions

View file

@ -170,6 +170,7 @@ final class Request
{
private array $get;
private array $server;
private array $attributes;
private function __construct()
{
@ -180,6 +181,7 @@ final class Request
$self = new self();
$self->get = $_GET;
$self->server = $_SERVER;
$self->attributes = [];
return $self;
}
@ -200,6 +202,18 @@ final class Request
return $this->server[$key] ?? $default;
}
public function withAttribute(string $name, $value = true): self
{
$clone = clone $this;
$clone->attributes[$name] = $value;
return $clone;
}
public function attribute(string $key, $default = null)
{
return $this->attributes[$key] ?? $default;
}
public function toArray(): array
{
return $this->get;