36 lines
811 B
PHP
36 lines
811 B
PHP
|
<?php
|
||
|
// ConnectionHeader.php
|
||
|
// Created: 2022-02-14
|
||
|
// Updated: 2022-02-27
|
||
|
|
||
|
namespace Index\Http\Headers;
|
||
|
|
||
|
use Index\Http\HttpHeader;
|
||
|
|
||
|
class ConnectionHeader {
|
||
|
private array $params;
|
||
|
|
||
|
public function __construct(array $params) {
|
||
|
$this->params = $params;
|
||
|
}
|
||
|
|
||
|
public function getParams(): array {
|
||
|
return $this->params;
|
||
|
}
|
||
|
|
||
|
public function hasParam(string $directive): bool {
|
||
|
return in_array($directive, $this->params);
|
||
|
}
|
||
|
|
||
|
public static function parse(HttpHeader $header): ConnectionHeader {
|
||
|
return new ConnectionHeader(
|
||
|
array_unique(
|
||
|
array_map(
|
||
|
fn($directive) => trim($directive),
|
||
|
explode(',', strtolower($header->getFirstLine()))
|
||
|
)
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
}
|