36 lines
749 B
PHP
36 lines
749 B
PHP
<?php
|
|
// HostHeader.php
|
|
// Created: 2022-02-14
|
|
// Updated: 2023-01-01
|
|
|
|
namespace Index\Http\Headers;
|
|
|
|
use Index\Http\HttpHeader;
|
|
|
|
class HostHeader {
|
|
private string $host;
|
|
private int $port;
|
|
|
|
public function __construct(string $host, int $port) {
|
|
$this->host = $host;
|
|
$this->port = $port;
|
|
}
|
|
|
|
public function getHost(): string {
|
|
return $this->host;
|
|
}
|
|
|
|
public function hasPort(): bool {
|
|
return $this->port > 0;
|
|
}
|
|
|
|
public function getPort(): int {
|
|
return $this->port;
|
|
}
|
|
|
|
public static function parse(HttpHeader $header): HostHeader {
|
|
$parts = explode(':', $header->getFirstLine(), 2);
|
|
return new HostHeader($parts[0], (int)($parts[1] ?? '-1'));
|
|
}
|
|
}
|