1: <?php declare(strict_types=1);
2:
3: namespace Salient\Contract\Http;
4:
5: use Psr\Http\Message\MessageInterface;
6: use Psr\Http\Message\RequestInterface;
7: use Psr\Http\Message\ResponseInterface;
8: use Salient\Contract\Core\Immutable;
9: use InvalidArgumentException;
10: use JsonSerializable;
11: use Stringable;
12:
13: /**
14: * @api
15: */
16: interface HttpMessageInterface extends
17: MessageInterface,
18: Stringable,
19: JsonSerializable,
20: Immutable
21: {
22: /**
23: * Get an instance of the class from a compatible PSR-7 message
24: *
25: * @template T of MessageInterface
26: *
27: * @param T $message
28: * @return T&HttpMessageInterface
29: * @throws InvalidArgumentException if the class cannot be instantiated from
30: * `$message`, e.g. if the class implements {@see RequestInterface} and
31: * `$message` is a {@see ResponseInterface}.
32: */
33: public static function fromPsr7(MessageInterface $message): HttpMessageInterface;
34:
35: /**
36: * Get the HTTP headers of the message
37: */
38: public function getHttpHeaders(): HttpHeadersInterface;
39:
40: /**
41: * Get the value of a message header as a list of values, splitting any
42: * comma-separated values
43: *
44: * @return string[]
45: */
46: public function getHeaderValues(string $name): array;
47:
48: /**
49: * Get the first value of a message header after splitting any
50: * comma-separated values
51: */
52: public function getFirstHeaderLine(string $name): string;
53:
54: /**
55: * Get the last value of a message header after splitting any
56: * comma-separated values
57: */
58: public function getLastHeaderLine(string $name): string;
59:
60: /**
61: * Get the only value of a message header after splitting any
62: * comma-separated values
63: *
64: * An exception is thrown if the header has more than one value.
65: */
66: public function getOneHeaderLine(string $name): string;
67:
68: /**
69: * Get the message as an HTTP payload
70: */
71: public function getHttpPayload(bool $withoutBody = false): string;
72:
73: /**
74: * Get the message as an HTTP Archive (HAR) object
75: *
76: * @return array{httpVersion:string,cookies:array<array{name:string,value:string,path?:string,domain?:string,expires?:string,httpOnly?:bool,secure?:bool}>,headers:array<array{name:string,value:string}>,headersSize:int,bodySize:int}
77: */
78: public function jsonSerialize(): array;
79: }
80: