Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
991 lars 3
declare(strict_types=1);
4
 
148 lars 5
namespace Psr\Http\Message;
6
 
7
/**
8
 * Representation of an incoming, server-side HTTP request.
9
 *
10
 * Per the HTTP specification, this interface includes properties for
11
 * each of the following:
12
 *
13
 * - Protocol version
14
 * - HTTP method
15
 * - URI
16
 * - Headers
17
 * - Message body
18
 *
19
 * Additionally, it encapsulates all data as it has arrived to the
20
 * application from the CGI and/or PHP environment, including:
21
 *
22
 * - The values represented in $_SERVER.
23
 * - Any cookies provided (generally via $_COOKIE)
24
 * - Query string arguments (generally via $_GET, or as parsed via parse_str())
25
 * - Upload files, if any (as represented by $_FILES)
26
 * - Deserialized body parameters (generally from $_POST)
27
 *
28
 * $_SERVER values MUST be treated as immutable, as they represent application
29
 * state at the time of request; as such, no methods are provided to allow
30
 * modification of those values. The other values provide such methods, as they
31
 * can be restored from $_SERVER or the request body, and may need treatment
32
 * during the application (e.g., body parameters may be deserialized based on
33
 * content type).
34
 *
35
 * Additionally, this interface recognizes the utility of introspecting a
36
 * request to derive and match additional parameters (e.g., via URI path
37
 * matching, decrypting cookie values, deserializing non-form-encoded body
38
 * content, matching authorization headers to users, etc). These parameters
39
 * are stored in an "attributes" property.
40
 *
41
 * Requests are considered immutable; all methods that might change state MUST
42
 * be implemented such that they retain the internal state of the current
43
 * message and return an instance that contains the changed state.
44
 */
45
interface ServerRequestInterface extends RequestInterface
46
{
47
    /**
48
     * Retrieve server parameters.
49
     *
50
     * Retrieves data related to the incoming request environment,
51
     * typically derived from PHP's $_SERVER superglobal. The data IS NOT
52
     * REQUIRED to originate from $_SERVER.
53
     *
54
     * @return array
55
     */
56
    public function getServerParams();
57
 
58
    /**
59
     * Retrieve cookies.
60
     *
61
     * Retrieves cookies sent by the client to the server.
62
     *
63
     * The data MUST be compatible with the structure of the $_COOKIE
64
     * superglobal.
65
     *
66
     * @return array
67
     */
68
    public function getCookieParams();
69
 
70
    /**
71
     * Return an instance with the specified cookies.
72
     *
73
     * The data IS NOT REQUIRED to come from the $_COOKIE superglobal, but MUST
74
     * be compatible with the structure of $_COOKIE. Typically, this data will
75
     * be injected at instantiation.
76
     *
77
     * This method MUST NOT update the related Cookie header of the request
78
     * instance, nor related values in the server params.
79
     *
80
     * This method MUST be implemented in such a way as to retain the
81
     * immutability of the message, and MUST return an instance that has the
82
     * updated cookie values.
83
     *
84
     * @param array $cookies Array of key/value pairs representing cookies.
85
     * @return static
86
     */
87
    public function withCookieParams(array $cookies);
88
 
89
    /**
90
     * Retrieve query string arguments.
91
     *
92
     * Retrieves the deserialized query string arguments, if any.
93
     *
94
     * Note: the query params might not be in sync with the URI or server
95
     * params. If you need to ensure you are only getting the original
96
     * values, you may need to parse the query string from `getUri()->getQuery()`
97
     * or from the `QUERY_STRING` server param.
98
     *
99
     * @return array
100
     */
101
    public function getQueryParams();
102
 
103
    /**
104
     * Return an instance with the specified query string arguments.
105
     *
106
     * These values SHOULD remain immutable over the course of the incoming
107
     * request. They MAY be injected during instantiation, such as from PHP's
108
     * $_GET superglobal, or MAY be derived from some other value such as the
109
     * URI. In cases where the arguments are parsed from the URI, the data
110
     * MUST be compatible with what PHP's parse_str() would return for
111
     * purposes of how duplicate query parameters are handled, and how nested
112
     * sets are handled.
113
     *
114
     * Setting query string arguments MUST NOT change the URI stored by the
115
     * request, nor the values in the server params.
116
     *
117
     * This method MUST be implemented in such a way as to retain the
118
     * immutability of the message, and MUST return an instance that has the
119
     * updated query string arguments.
120
     *
121
     * @param array $query Array of query string arguments, typically from
122
     *     $_GET.
123
     * @return static
124
     */
125
    public function withQueryParams(array $query);
126
 
127
    /**
128
     * Retrieve normalized file upload data.
129
     *
130
     * This method returns upload metadata in a normalized tree, with each leaf
131
     * an instance of Psr\Http\Message\UploadedFileInterface.
132
     *
133
     * These values MAY be prepared from $_FILES or the message body during
134
     * instantiation, or MAY be injected via withUploadedFiles().
135
     *
136
     * @return array An array tree of UploadedFileInterface instances; an empty
137
     *     array MUST be returned if no data is present.
138
     */
139
    public function getUploadedFiles();
140
 
141
    /**
142
     * Create a new instance with the specified uploaded files.
143
     *
144
     * This method MUST be implemented in such a way as to retain the
145
     * immutability of the message, and MUST return an instance that has the
146
     * updated body parameters.
147
     *
148
     * @param array $uploadedFiles An array tree of UploadedFileInterface instances.
149
     * @return static
150
     * @throws \InvalidArgumentException if an invalid structure is provided.
151
     */
152
    public function withUploadedFiles(array $uploadedFiles);
153
 
154
    /**
155
     * Retrieve any parameters provided in the request body.
156
     *
157
     * If the request Content-Type is either application/x-www-form-urlencoded
158
     * or multipart/form-data, and the request method is POST, this method MUST
159
     * return the contents of $_POST.
160
     *
161
     * Otherwise, this method may return any results of deserializing
162
     * the request body content; as parsing returns structured content, the
163
     * potential types MUST be arrays or objects only. A null value indicates
164
     * the absence of body content.
165
     *
166
     * @return null|array|object The deserialized body parameters, if any.
167
     *     These will typically be an array or object.
168
     */
169
    public function getParsedBody();
170
 
171
    /**
172
     * Return an instance with the specified body parameters.
173
     *
174
     * These MAY be injected during instantiation.
175
     *
176
     * If the request Content-Type is either application/x-www-form-urlencoded
177
     * or multipart/form-data, and the request method is POST, use this method
178
     * ONLY to inject the contents of $_POST.
179
     *
180
     * The data IS NOT REQUIRED to come from $_POST, but MUST be the results of
181
     * deserializing the request body content. Deserialization/parsing returns
182
     * structured data, and, as such, this method ONLY accepts arrays or objects,
183
     * or a null value if nothing was available to parse.
184
     *
185
     * As an example, if content negotiation determines that the request data
186
     * is a JSON payload, this method could be used to create a request
187
     * instance with the deserialized parameters.
188
     *
189
     * This method MUST be implemented in such a way as to retain the
190
     * immutability of the message, and MUST return an instance that has the
191
     * updated body parameters.
192
     *
193
     * @param null|array|object $data The deserialized body data. This will
194
     *     typically be in an array or object.
195
     * @return static
196
     * @throws \InvalidArgumentException if an unsupported argument type is
197
     *     provided.
198
     */
199
    public function withParsedBody($data);
200
 
201
    /**
202
     * Retrieve attributes derived from the request.
203
     *
204
     * The request "attributes" may be used to allow injection of any
205
     * parameters derived from the request: e.g., the results of path
206
     * match operations; the results of decrypting cookies; the results of
207
     * deserializing non-form-encoded message bodies; etc. Attributes
208
     * will be application and request specific, and CAN be mutable.
209
     *
210
     * @return array Attributes derived from the request.
211
     */
212
    public function getAttributes();
213
 
214
    /**
215
     * Retrieve a single derived request attribute.
216
     *
217
     * Retrieves a single derived request attribute as described in
218
     * getAttributes(). If the attribute has not been previously set, returns
219
     * the default value as provided.
220
     *
221
     * This method obviates the need for a hasAttribute() method, as it allows
222
     * specifying a default value to return if the attribute is not found.
223
     *
224
     * @see getAttributes()
225
     * @param string $name The attribute name.
226
     * @param mixed $default Default value to return if the attribute does not exist.
227
     * @return mixed
228
     */
991 lars 229
    public function getAttribute(string $name, $default = null);
148 lars 230
 
231
    /**
232
     * Return an instance with the specified derived request attribute.
233
     *
234
     * This method allows setting a single derived request attribute as
235
     * described in getAttributes().
236
     *
237
     * This method MUST be implemented in such a way as to retain the
238
     * immutability of the message, and MUST return an instance that has the
239
     * updated attribute.
240
     *
241
     * @see getAttributes()
242
     * @param string $name The attribute name.
243
     * @param mixed $value The value of the attribute.
244
     * @return static
245
     */
991 lars 246
    public function withAttribute(string $name, $value);
148 lars 247
 
248
    /**
249
     * Return an instance that removes the specified derived request attribute.
250
     *
251
     * This method allows removing a single derived request attribute as
252
     * described in getAttributes().
253
     *
254
     * This method MUST be implemented in such a way as to retain the
255
     * immutability of the message, and MUST return an instance that removes
256
     * the attribute.
257
     *
258
     * @see getAttributes()
259
     * @param string $name The attribute name.
260
     * @return static
261
     */
991 lars 262
    public function withoutAttribute(string $name);
148 lars 263
}