modify
This commit is contained in:
@@ -16,88 +16,88 @@ namespace HttpServer\Http;
|
|||||||
trait HttpHeaders
|
trait HttpHeaders
|
||||||
{
|
{
|
||||||
|
|
||||||
private array $_headers = [];
|
private array $_headers = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
*/
|
*/
|
||||||
public function setHeaders(array $headers): void
|
public function setHeaders(array $headers): void
|
||||||
{
|
{
|
||||||
$this->_headers = $headers;
|
$this->_headers = $headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
{
|
{
|
||||||
return $this->_headers;
|
return $this->_headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
* @return mixed|null
|
* @return mixed|null
|
||||||
*/
|
*/
|
||||||
public function getHeader($name): mixed
|
public function getHeader($name, $default = null): mixed
|
||||||
{
|
{
|
||||||
return $this->_headers[$name];
|
return $this->_headers[$name] ?? $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getContentType(): string
|
public function getContentType(): string
|
||||||
{
|
{
|
||||||
return $this->_headers['content-type'] ?? '';
|
return $this->_headers['content-type'] ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getRequestUri(): ?string
|
public function getRequestUri(): ?string
|
||||||
{
|
{
|
||||||
return $this->_headers['request_uri'];
|
return $this->_headers['request_uri'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getRequestMethod(): ?string
|
public function getRequestMethod(): ?string
|
||||||
{
|
{
|
||||||
return $this->_headers['request_method'];
|
return $this->_headers['request_method'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getAgent(): mixed
|
public function getAgent(): mixed
|
||||||
{
|
{
|
||||||
return $this->_headers['user-agent'];
|
return $this->_headers['user-agent'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function exists($name): bool
|
public function exists($name): bool
|
||||||
{
|
{
|
||||||
return $this->_headers[$name] ?? null === null;
|
return $this->_headers[$name] ?? null === null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getHeaders(): array
|
public function getHeaders(): array
|
||||||
{
|
{
|
||||||
return $this->_headers;
|
return $this->_headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user