3
declare(strict_types=1);
6
* This file is part of CodeIgniter 4 framework.
8
* (c) CodeIgniter Foundation <admin@codeigniter.com>
10
* For the full copyright and license information, please view
11
* the LICENSE file that was distributed with this source code.
14
namespace CodeIgniter\HTTP;
16
use InvalidArgumentException;
21
* @see \CodeIgniter\HTTP\MessageTest
23
class Message implements MessageInterface
32
protected $protocolVersion;
35
* List of valid protocol versions
39
protected $validProtocolVersions = [
54
* Returns the Message's body.
58
public function getBody()
64
* Returns an array containing all headers.
66
* @return array<string, Header> An array of the request headers
68
* @deprecated Use Message::headers() to make room for PSR-7
70
* @TODO Incompatible return value with PSR-7
74
public function getHeaders(): array
76
return $this->headers();
80
* Returns a single header object. If multiple headers with the same
81
* name exist, then will return an array of header objects.
83
* @return array|Header|null
85
* @deprecated Use Message::header() to make room for PSR-7
87
* @TODO Incompatible return value with PSR-7
91
public function getHeader(string $name)
93
return $this->header($name);
97
* Determines whether a header exists.
99
public function hasHeader(string $name): bool
101
$origName = $this->getHeaderName($name);
103
return isset($this->headers[$origName]);
107
* Retrieves a comma-separated string of the values for a single header.
109
* This method returns all of the header values of the given
110
* case-insensitive header name as a string concatenated together using
113
* NOTE: Not all header values may be appropriately represented using
114
* comma concatenation. For such headers, use getHeader() instead
115
* and supply your own delimiter when concatenating.
117
public function getHeaderLine(string $name): string
119
if ($this->hasMultipleHeaders($name)) {
120
throw new InvalidArgumentException(
121
'The header "' . $name . '" already has multiple headers.'
122
. ' You cannot use getHeaderLine().'
126
$origName = $this->getHeaderName($name);
128
if (! array_key_exists($origName, $this->headers)) {
132
return $this->headers[$origName]->getValueLine();
136
* Returns the HTTP Protocol Version.
138
public function getProtocolVersion(): string
140
return $this->protocolVersion ?? '1.1';