This commit is contained in:
as2252258@163.com
2021-08-06 02:03:01 +08:00
parent f4acafe8de
commit 857d5c0e13
+62 -62
View File
@@ -16,88 +16,88 @@ 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): mixed
{
return $this->_headers[$name];
}
/**
* @param $name
* @return mixed|null
*/
public function getHeader($name, $default = null): mixed
{
return $this->_headers[$name] ?? $default;
}
/**
* @return string
*/
public function getContentType(): string
{
/**
* @return string
*/
public function getContentType(): string
{
return $this->_headers['content-type'] ?? '';
}
}
/**
* @return string|null
*/
public function getRequestUri(): ?string
{
/**
* @return string|null
*/
public function getRequestUri(): ?string
{
return $this->_headers['request_uri'];
}
}
/**
* @return string|null
*/
public function getRequestMethod(): ?string
{
/**
* @return string|null
*/
public function getRequestMethod(): ?string
{
return $this->_headers['request_method'];
}
}
/**
* @return mixed
*/
public function getAgent(): mixed
{
/**
* @return mixed
*/
public function getAgent(): mixed
{
return $this->_headers['user-agent'];
}
}
/**
* @param $name
* @return bool
*/
public function exists($name): bool
{
return $this->_headers[$name] ?? null === null;
}
/**
* @param $name
* @return bool
*/
public function exists($name): bool
{
return $this->_headers[$name] ?? null === null;
}
/**
* @return array
*/
public function getHeaders(): array
{
return $this->_headers;
}
/**
* @return array
*/
public function getHeaders(): array
{
return $this->_headers;
}
}