This commit is contained in:
2021-08-27 17:46:40 +08:00
parent 79c8f1f799
commit 151ac4ac0e
3 changed files with 87 additions and 32 deletions
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace Server\Message;
class Headers
{
private array $headers = [];
/**
* @param array $headers
* @return $this
*/
public function withHeader(array $headers): static
{
$class = clone $this;
$class->headers = $headers;
return $class;
}
/**
* @param $name
* @param null $default
* @return string|array|float|int|null
*/
public function get($name, $default = null): string|array|float|int|null
{
return $this->headers[$name] ?? $default;
}
/**
* @return array
*/
public function toArray(): array
{
return $this->headers;
}
}