This commit is contained in:
2021-08-06 11:03:49 +08:00
parent 86d6f5a346
commit 0d03334891
2 changed files with 82 additions and 71 deletions
+78 -66
View File
@@ -16,88 +16,100 @@ namespace HttpServer\Http;
trait HttpHeaders
{
private array $_headers = [];
private array $_headers = [];
/**
* @param array $headers
*/
public function setHeaders(array $headers): void
{
$this->_headers = $headers;
}
/**
* @param array $headers
*/
public function setHeaders(array $headers): void
{
$this->_headers = $headers;
}
/**
* @return array
*/
public function toArray(): array
{
return $this->_headers;
}
/**
* @return array
*/
public function toArray(): array
{
return $this->_headers;
}
/**
* @param $name
* @return mixed|null
*/
public function getHeader($name, $default = null): mixed
{
return $this->_headers[$name] ?? $default;
}
/**
* @param $name
* @param null $default
* @return mixed
*/
public function getHeader($name, $default = null): mixed
{
return $this->_headers[$name] ?? $default;
}
/**
* @return string
*/
public function getContentType(): string
{
return $this->_headers['content-type'] ?? '';
}
/**
* @param $name
* @param $default
* @return mixed
*/
public function header($name, $default = null): mixed
{
return $this->getHeader($name, $default);
}
/**
* @return string|null
*/
public function getRequestUri(): ?string
{
return $this->_headers['request_uri'];
}
/**
* @return string
*/
public function getContentType(): string
{
return $this->_headers['content-type'] ?? '';
}
/**
* @return string|null
*/
public function getRequestMethod(): ?string
{
return $this->_headers['request_method'];
}
/**
* @return string|null
*/
public function getRequestUri(): ?string
{
return $this->_headers['request_uri'];
}
/**
* @return mixed
*/
public function getAgent(): mixed
{
return $this->_headers['user-agent'];
}
/**
* @return string|null
*/
public function getRequestMethod(): ?string
{
return $this->_headers['request_method'];
}
/**
* @param $name
* @return bool
*/
public function exists($name): bool
{
return $this->_headers[$name] ?? null === null;
}
/**
* @return mixed
*/
public function getAgent(): mixed
{
return $this->_headers['user-agent'];
}
/**
* @return array
*/
public function getHeaders(): array
{
return $this->_headers;
}
/**
* @param $name
* @return bool
*/
public function exists($name): bool
{
return $this->_headers[$name] ?? null === null;
}
/**
* @return array
*/
public function getHeaders(): array
{
return $this->_headers;
}
}