Files
kiri-core/HttpServer/Http/HttpHeaders.php
T

104 lines
1.3 KiB
PHP
Raw Normal View History

2020-08-31 01:27:08 +08:00
<?php
/**
* Created by PhpStorm.
* User: admin
* Date: 2019-03-18
* Time: 14:54
*/
2020-10-29 18:17:25 +08:00
declare(strict_types=1);
2020-12-25 15:57:52 +08:00
2020-08-31 01:27:08 +08:00
namespace HttpServer\Http;
/**
* Class HttpHeaders
2020-08-31 12:38:32 +08:00
* @package Snowflake\Snowflake\Http
2020-08-31 01:27:08 +08:00
*/
2021-08-06 00:50:25 +08:00
trait HttpHeaders
2020-08-31 01:27:08 +08:00
{
2021-08-05 19:14:08 +08:00
private array $_headers = [];
/**
* @param array $headers
*/
public function setHeaders(array $headers): void
{
$this->_headers = $headers;
}
2021-04-07 14:07:18 +08:00
/**
2021-08-02 11:07:15 +08:00
* @return array
2021-04-07 14:07:18 +08:00
*/
2021-08-02 11:07:15 +08:00
public function toArray(): array
2021-04-07 14:07:18 +08:00
{
2021-08-05 22:47:10 +08:00
return $this->_headers;
2021-04-07 14:07:18 +08:00
}
/**
2021-08-02 11:07:15 +08:00
* @param $name
* @return mixed|null
2021-04-07 14:07:18 +08:00
*/
2021-08-02 11:07:15 +08:00
public function getHeader($name): ?string
2021-04-07 14:07:18 +08:00
{
2021-08-05 22:47:10 +08:00
return $this->_headers[$name];
2021-04-07 14:07:18 +08:00
}
2020-08-31 01:27:08 +08:00
/**
2021-08-02 11:07:15 +08:00
* @return string
2020-08-31 01:27:08 +08:00
*/
2021-08-02 11:07:15 +08:00
public function getContentType(): string
2020-08-31 01:27:08 +08:00
{
2021-08-05 22:50:31 +08:00
return $this->_headers['content-type'] ?? '';
2020-08-31 01:27:08 +08:00
}
2021-08-01 15:16:50 +08:00
/**
2021-08-02 11:07:15 +08:00
* @return string|null
2021-08-01 15:16:50 +08:00
*/
2021-08-02 11:07:15 +08:00
public function getRequestUri(): ?string
2021-08-01 15:16:50 +08:00
{
2021-08-05 22:47:10 +08:00
return $this->_headers['request_uri'];
2021-08-01 15:16:50 +08:00
}
2020-09-02 14:28:21 +08:00
/**
2021-08-02 11:07:15 +08:00
* @return string|null
2020-09-02 14:28:21 +08:00
*/
2021-08-02 11:07:15 +08:00
public function getRequestMethod(): ?string
2020-09-02 14:28:21 +08:00
{
2021-08-05 22:47:10 +08:00
return $this->_headers['request_method'];
2020-08-31 01:27:08 +08:00
}
/**
2020-12-25 15:57:52 +08:00
* @return mixed
2020-08-31 01:27:08 +08:00
*/
2021-08-02 11:07:15 +08:00
public function getAgent(): mixed
2020-08-31 01:27:08 +08:00
{
2021-08-05 22:47:10 +08:00
return $this->_headers['user-agent'];
2020-08-31 01:27:08 +08:00
}
/**
2021-08-01 15:03:49 +08:00
* @param $name
* @return bool
2020-08-31 01:27:08 +08:00
*/
2021-08-01 15:03:49 +08:00
public function exists($name): bool
2020-08-31 01:27:08 +08:00
{
2021-08-05 22:47:10 +08:00
return $this->_headers[$name] ?? null === null;
2020-08-31 01:27:08 +08:00
}
2021-07-27 18:21:30 +08:00
/**
2021-08-01 15:03:49 +08:00
* @return array
2021-07-27 18:21:30 +08:00
*/
2021-08-01 15:03:49 +08:00
public function getHeaders(): array
2021-07-27 18:21:30 +08:00
{
2021-08-05 22:47:10 +08:00
return $this->_headers;
2021-08-02 11:07:15 +08:00
}
2020-08-31 01:27:08 +08:00
}