index/src/Http/HttpMessage.php

84 lines
2.1 KiB
PHP

<?php
// HttpMessage.php
// Created: 2022-02-08
// Updated: 2022-02-27
namespace Index\Http;
use Index\Version;
use Index\IO\Stream;
use Index\Http\Content\IHttpContent;
use Index\Http\Content\BencodedContent;
use Index\Http\Content\FormContent;
use Index\Http\Content\JsonContent;
use Index\Http\Content\StreamContent;
use Index\Http\Content\StringContent;
abstract class HttpMessage {
private Version $version;
private HttpHeaders $headers;
private ?IHttpContent $content;
public function __construct(Version $version, HttpHeaders $headers, ?IHttpContent $content) {
$this->version = $version;
$this->headers = $headers;
$this->content = $content;
}
public function getHttpVersion(): Version {
return $this->version;
}
public function getHeaders(): array {
return $this->headers->getHeaders();
}
public function hasHeader(string $name): bool {
return $this->headers->hasHeader($name);
}
public function getHeader(string $name): HttpHeader {
return $this->headers->getHeader($name);
}
public function getHeaderLine(string $name): string {
return $this->headers->getHeaderLine($name);
}
public function getHeaderLines(string $name): array {
return $this->headers->getHeaderLines($name);
}
public function getHeaderFirstLine(string $name): string {
return $this->headers->getHeaderFirstLine($name);
}
public function hasContent(): bool {
return $this->content !== null;
}
public function getContent(): ?IHttpContent {
return $this->content;
}
public function isJsonContent(): bool {
return $this->content instanceof JsonContent;
}
public function isFormContent(): bool {
return $this->content instanceof FormContent;
}
public function isStreamContent(): bool {
return $this->content instanceof StreamContent;
}
public function isStringContent(): bool {
return $this->content instanceof StringContent;
}
public function isBencodedContent(): bool {
return $this->content instanceof BencodedContent;
}
}