57 lines
1.1 KiB
PHP
57 lines
1.1 KiB
PHP
<?php
|
|
// HttpHeader.php
|
|
// Created: 2022-02-14
|
|
// Updated: 2024-08-01
|
|
|
|
namespace Index\Http;
|
|
|
|
use Stringable;
|
|
|
|
/**
|
|
* Represents a generic HTTP header.
|
|
*/
|
|
class HttpHeader implements Stringable {
|
|
private array $lines;
|
|
|
|
/**
|
|
* @param string $name Name of the header.
|
|
* @param string ...$lines Lines of the header.
|
|
*/
|
|
public function __construct(
|
|
private string $name,
|
|
string ...$lines
|
|
) {
|
|
$this->lines = $lines;
|
|
}
|
|
|
|
/**
|
|
* Retrieves the name of the header.
|
|
*
|
|
* @return string Header name.
|
|
*/
|
|
public function getName(): string {
|
|
return $this->name;
|
|
}
|
|
|
|
/**
|
|
* Retrieves lines of the header.
|
|
*
|
|
* @return string[] Header lines.
|
|
*/
|
|
public function getLines(): array {
|
|
return $this->lines;
|
|
}
|
|
|
|
/**
|
|
* Retrieves the first line of the header.
|
|
*
|
|
* @return string First header line.
|
|
*/
|
|
public function getFirstLine(): string {
|
|
return $this->lines[0];
|
|
}
|
|
|
|
public function __toString(): string {
|
|
return implode(', ', $this->lines);
|
|
}
|
|
}
|