36 lines
750 B
PHP
36 lines
750 B
PHP
|
<?php
|
||
|
// HostHeader.php
|
||
|
// Created: 2022-02-14
|
||
|
// Updated: 2022-02-14
|
||
|
|
||
|
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], intval($parts[1] ?? '-1'));
|
||
|
}
|
||
|
}
|