ci4

Форк
0
/
Message.php 
142 строки · 3.1 Кб
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace CodeIgniter\HTTP;
15

16
use InvalidArgumentException;
17

18
/**
19
 * An HTTP message
20
 *
21
 * @see \CodeIgniter\HTTP\MessageTest
22
 */
23
class Message implements MessageInterface
24
{
25
    use MessageTrait;
26

27
    /**
28
     * Protocol version
29
     *
30
     * @var string
31
     */
32
    protected $protocolVersion;
33

34
    /**
35
     * List of valid protocol versions
36
     *
37
     * @var array
38
     */
39
    protected $validProtocolVersions = [
40
        '1.0',
41
        '1.1',
42
        '2.0',
43
        '3.0',
44
    ];
45

46
    /**
47
     * Message body
48
     *
49
     * @var string|null
50
     */
51
    protected $body;
52

53
    /**
54
     * Returns the Message's body.
55
     *
56
     * @return string|null
57
     */
58
    public function getBody()
59
    {
60
        return $this->body;
61
    }
62

63
    /**
64
     * Returns an array containing all headers.
65
     *
66
     * @return array<string, Header> An array of the request headers
67
     *
68
     * @deprecated Use Message::headers() to make room for PSR-7
69
     *
70
     * @TODO Incompatible return value with PSR-7
71
     *
72
     * @codeCoverageIgnore
73
     */
74
    public function getHeaders(): array
75
    {
76
        return $this->headers();
77
    }
78

79
    /**
80
     * Returns a single header object. If multiple headers with the same
81
     * name exist, then will return an array of header objects.
82
     *
83
     * @return array|Header|null
84
     *
85
     * @deprecated Use Message::header() to make room for PSR-7
86
     *
87
     * @TODO Incompatible return value with PSR-7
88
     *
89
     * @codeCoverageIgnore
90
     */
91
    public function getHeader(string $name)
92
    {
93
        return $this->header($name);
94
    }
95

96
    /**
97
     * Determines whether a header exists.
98
     */
99
    public function hasHeader(string $name): bool
100
    {
101
        $origName = $this->getHeaderName($name);
102

103
        return isset($this->headers[$origName]);
104
    }
105

106
    /**
107
     * Retrieves a comma-separated string of the values for a single header.
108
     *
109
     * This method returns all of the header values of the given
110
     * case-insensitive header name as a string concatenated together using
111
     * a comma.
112
     *
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.
116
     */
117
    public function getHeaderLine(string $name): string
118
    {
119
        if ($this->hasMultipleHeaders($name)) {
120
            throw new InvalidArgumentException(
121
                'The header "' . $name . '" already has multiple headers.'
122
                . ' You cannot use getHeaderLine().'
123
            );
124
        }
125

126
        $origName = $this->getHeaderName($name);
127

128
        if (! array_key_exists($origName, $this->headers)) {
129
            return '';
130
        }
131

132
        return $this->headers[$origName]->getValueLine();
133
    }
134

135
    /**
136
     * Returns the HTTP Protocol Version.
137
     */
138
    public function getProtocolVersion(): string
139
    {
140
        return $this->protocolVersion ?? '1.1';
141
    }
142
}
143

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.