| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace GuzzleHttp\Psr7;
|
|
|
4 |
|
|
|
5 |
use Psr\Http\Message\MessageInterface;
|
|
|
6 |
use Psr\Http\Message\RequestInterface;
|
|
|
7 |
use Psr\Http\Message\StreamInterface;
|
|
|
8 |
use Psr\Http\Message\UriInterface;
|
|
|
9 |
|
|
|
10 |
/**
|
|
|
11 |
* Returns the string representation of an HTTP message.
|
|
|
12 |
*
|
|
|
13 |
* @param MessageInterface $message Message to convert to a string.
|
|
|
14 |
*
|
|
|
15 |
* @return string
|
|
|
16 |
*
|
|
|
17 |
* @deprecated str will be removed in guzzlehttp/psr7:2.0. Use Message::toString instead.
|
|
|
18 |
*/
|
|
|
19 |
function str(MessageInterface $message)
|
|
|
20 |
{
|
|
|
21 |
return Message::toString($message);
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Returns a UriInterface for the given value.
|
|
|
26 |
*
|
|
|
27 |
* This function accepts a string or UriInterface and returns a
|
|
|
28 |
* UriInterface for the given value. If the value is already a
|
|
|
29 |
* UriInterface, it is returned as-is.
|
|
|
30 |
*
|
|
|
31 |
* @param string|UriInterface $uri
|
|
|
32 |
*
|
|
|
33 |
* @return UriInterface
|
|
|
34 |
*
|
|
|
35 |
* @throws \InvalidArgumentException
|
|
|
36 |
*
|
|
|
37 |
* @deprecated uri_for will be removed in guzzlehttp/psr7:2.0. Use Utils::uriFor instead.
|
|
|
38 |
*/
|
|
|
39 |
function uri_for($uri)
|
|
|
40 |
{
|
|
|
41 |
return Utils::uriFor($uri);
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* Create a new stream based on the input type.
|
|
|
46 |
*
|
|
|
47 |
* Options is an associative array that can contain the following keys:
|
|
|
48 |
* - metadata: Array of custom metadata.
|
|
|
49 |
* - size: Size of the stream.
|
|
|
50 |
*
|
|
|
51 |
* This method accepts the following `$resource` types:
|
|
|
52 |
* - `Psr\Http\Message\StreamInterface`: Returns the value as-is.
|
|
|
53 |
* - `string`: Creates a stream object that uses the given string as the contents.
|
|
|
54 |
* - `resource`: Creates a stream object that wraps the given PHP stream resource.
|
|
|
55 |
* - `Iterator`: If the provided value implements `Iterator`, then a read-only
|
|
|
56 |
* stream object will be created that wraps the given iterable. Each time the
|
|
|
57 |
* stream is read from, data from the iterator will fill a buffer and will be
|
|
|
58 |
* continuously called until the buffer is equal to the requested read size.
|
|
|
59 |
* Subsequent read calls will first read from the buffer and then call `next`
|
|
|
60 |
* on the underlying iterator until it is exhausted.
|
|
|
61 |
* - `object` with `__toString()`: If the object has the `__toString()` method,
|
|
|
62 |
* the object will be cast to a string and then a stream will be returned that
|
|
|
63 |
* uses the string value.
|
|
|
64 |
* - `NULL`: When `null` is passed, an empty stream object is returned.
|
|
|
65 |
* - `callable` When a callable is passed, a read-only stream object will be
|
|
|
66 |
* created that invokes the given callable. The callable is invoked with the
|
|
|
67 |
* number of suggested bytes to read. The callable can return any number of
|
|
|
68 |
* bytes, but MUST return `false` when there is no more data to return. The
|
|
|
69 |
* stream object that wraps the callable will invoke the callable until the
|
|
|
70 |
* number of requested bytes are available. Any additional bytes will be
|
|
|
71 |
* buffered and used in subsequent reads.
|
|
|
72 |
*
|
|
|
73 |
* @param resource|string|null|int|float|bool|StreamInterface|callable|\Iterator $resource Entity body data
|
|
|
74 |
* @param array $options Additional options
|
|
|
75 |
*
|
|
|
76 |
* @return StreamInterface
|
|
|
77 |
*
|
|
|
78 |
* @throws \InvalidArgumentException if the $resource arg is not valid.
|
|
|
79 |
*
|
|
|
80 |
* @deprecated stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.
|
|
|
81 |
*/
|
|
|
82 |
function stream_for($resource = '', array $options = [])
|
|
|
83 |
{
|
|
|
84 |
return Utils::streamFor($resource, $options);
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* Parse an array of header values containing ";" separated data into an
|
|
|
89 |
* array of associative arrays representing the header key value pair data
|
|
|
90 |
* of the header. When a parameter does not contain a value, but just
|
|
|
91 |
* contains a key, this function will inject a key with a '' string value.
|
|
|
92 |
*
|
|
|
93 |
* @param string|array $header Header to parse into components.
|
|
|
94 |
*
|
|
|
95 |
* @return array Returns the parsed header values.
|
|
|
96 |
*
|
|
|
97 |
* @deprecated parse_header will be removed in guzzlehttp/psr7:2.0. Use Header::parse instead.
|
|
|
98 |
*/
|
|
|
99 |
function parse_header($header)
|
|
|
100 |
{
|
|
|
101 |
return Header::parse($header);
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
/**
|
|
|
105 |
* Converts an array of header values that may contain comma separated
|
|
|
106 |
* headers into an array of headers with no comma separated values.
|
|
|
107 |
*
|
|
|
108 |
* @param string|array $header Header to normalize.
|
|
|
109 |
*
|
|
|
110 |
* @return array Returns the normalized header field values.
|
|
|
111 |
*
|
|
|
112 |
* @deprecated normalize_header will be removed in guzzlehttp/psr7:2.0. Use Header::normalize instead.
|
|
|
113 |
*/
|
|
|
114 |
function normalize_header($header)
|
|
|
115 |
{
|
|
|
116 |
return Header::normalize($header);
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
/**
|
|
|
120 |
* Clone and modify a request with the given changes.
|
|
|
121 |
*
|
|
|
122 |
* This method is useful for reducing the number of clones needed to mutate a
|
|
|
123 |
* message.
|
|
|
124 |
*
|
|
|
125 |
* The changes can be one of:
|
|
|
126 |
* - method: (string) Changes the HTTP method.
|
|
|
127 |
* - set_headers: (array) Sets the given headers.
|
|
|
128 |
* - remove_headers: (array) Remove the given headers.
|
|
|
129 |
* - body: (mixed) Sets the given body.
|
|
|
130 |
* - uri: (UriInterface) Set the URI.
|
|
|
131 |
* - query: (string) Set the query string value of the URI.
|
|
|
132 |
* - version: (string) Set the protocol version.
|
|
|
133 |
*
|
|
|
134 |
* @param RequestInterface $request Request to clone and modify.
|
|
|
135 |
* @param array $changes Changes to apply.
|
|
|
136 |
*
|
|
|
137 |
* @return RequestInterface
|
|
|
138 |
*
|
|
|
139 |
* @deprecated modify_request will be removed in guzzlehttp/psr7:2.0. Use Utils::modifyRequest instead.
|
|
|
140 |
*/
|
|
|
141 |
function modify_request(RequestInterface $request, array $changes)
|
|
|
142 |
{
|
|
|
143 |
return Utils::modifyRequest($request, $changes);
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
/**
|
|
|
147 |
* Attempts to rewind a message body and throws an exception on failure.
|
|
|
148 |
*
|
|
|
149 |
* The body of the message will only be rewound if a call to `tell()` returns a
|
|
|
150 |
* value other than `0`.
|
|
|
151 |
*
|
|
|
152 |
* @param MessageInterface $message Message to rewind
|
|
|
153 |
*
|
|
|
154 |
* @throws \RuntimeException
|
|
|
155 |
*
|
|
|
156 |
* @deprecated rewind_body will be removed in guzzlehttp/psr7:2.0. Use Message::rewindBody instead.
|
|
|
157 |
*/
|
|
|
158 |
function rewind_body(MessageInterface $message)
|
|
|
159 |
{
|
|
|
160 |
Message::rewindBody($message);
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
/**
|
|
|
164 |
* Safely opens a PHP stream resource using a filename.
|
|
|
165 |
*
|
|
|
166 |
* When fopen fails, PHP normally raises a warning. This function adds an
|
|
|
167 |
* error handler that checks for errors and throws an exception instead.
|
|
|
168 |
*
|
|
|
169 |
* @param string $filename File to open
|
|
|
170 |
* @param string $mode Mode used to open the file
|
|
|
171 |
*
|
|
|
172 |
* @return resource
|
|
|
173 |
*
|
|
|
174 |
* @throws \RuntimeException if the file cannot be opened
|
|
|
175 |
*
|
|
|
176 |
* @deprecated try_fopen will be removed in guzzlehttp/psr7:2.0. Use Utils::tryFopen instead.
|
|
|
177 |
*/
|
|
|
178 |
function try_fopen($filename, $mode)
|
|
|
179 |
{
|
|
|
180 |
return Utils::tryFopen($filename, $mode);
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
/**
|
|
|
184 |
* Copy the contents of a stream into a string until the given number of
|
|
|
185 |
* bytes have been read.
|
|
|
186 |
*
|
|
|
187 |
* @param StreamInterface $stream Stream to read
|
|
|
188 |
* @param int $maxLen Maximum number of bytes to read. Pass -1
|
|
|
189 |
* to read the entire stream.
|
|
|
190 |
* @return string
|
|
|
191 |
*
|
|
|
192 |
* @throws \RuntimeException on error.
|
|
|
193 |
*
|
|
|
194 |
* @deprecated copy_to_string will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToString instead.
|
|
|
195 |
*/
|
|
|
196 |
function copy_to_string(StreamInterface $stream, $maxLen = -1)
|
|
|
197 |
{
|
|
|
198 |
return Utils::copyToString($stream, $maxLen);
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
/**
|
|
|
202 |
* Copy the contents of a stream into another stream until the given number
|
|
|
203 |
* of bytes have been read.
|
|
|
204 |
*
|
|
|
205 |
* @param StreamInterface $source Stream to read from
|
|
|
206 |
* @param StreamInterface $dest Stream to write to
|
|
|
207 |
* @param int $maxLen Maximum number of bytes to read. Pass -1
|
|
|
208 |
* to read the entire stream.
|
|
|
209 |
*
|
|
|
210 |
* @throws \RuntimeException on error.
|
|
|
211 |
*
|
|
|
212 |
* @deprecated copy_to_stream will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToStream instead.
|
|
|
213 |
*/
|
|
|
214 |
function copy_to_stream(StreamInterface $source, StreamInterface $dest, $maxLen = -1)
|
|
|
215 |
{
|
|
|
216 |
return Utils::copyToStream($source, $dest, $maxLen);
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
/**
|
|
|
220 |
* Calculate a hash of a stream.
|
|
|
221 |
*
|
|
|
222 |
* This method reads the entire stream to calculate a rolling hash, based on
|
|
|
223 |
* PHP's `hash_init` functions.
|
|
|
224 |
*
|
|
|
225 |
* @param StreamInterface $stream Stream to calculate the hash for
|
|
|
226 |
* @param string $algo Hash algorithm (e.g. md5, crc32, etc)
|
|
|
227 |
* @param bool $rawOutput Whether or not to use raw output
|
|
|
228 |
*
|
|
|
229 |
* @return string Returns the hash of the stream
|
|
|
230 |
*
|
|
|
231 |
* @throws \RuntimeException on error.
|
|
|
232 |
*
|
|
|
233 |
* @deprecated hash will be removed in guzzlehttp/psr7:2.0. Use Utils::hash instead.
|
|
|
234 |
*/
|
|
|
235 |
function hash(StreamInterface $stream, $algo, $rawOutput = false)
|
|
|
236 |
{
|
|
|
237 |
return Utils::hash($stream, $algo, $rawOutput);
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
/**
|
|
|
241 |
* Read a line from the stream up to the maximum allowed buffer length.
|
|
|
242 |
*
|
|
|
243 |
* @param StreamInterface $stream Stream to read from
|
|
|
244 |
* @param int|null $maxLength Maximum buffer length
|
|
|
245 |
*
|
|
|
246 |
* @return string
|
|
|
247 |
*
|
|
|
248 |
* @deprecated readline will be removed in guzzlehttp/psr7:2.0. Use Utils::readLine instead.
|
|
|
249 |
*/
|
|
|
250 |
function readline(StreamInterface $stream, $maxLength = null)
|
|
|
251 |
{
|
|
|
252 |
return Utils::readLine($stream, $maxLength);
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
/**
|
|
|
256 |
* Parses a request message string into a request object.
|
|
|
257 |
*
|
|
|
258 |
* @param string $message Request message string.
|
|
|
259 |
*
|
|
|
260 |
* @return Request
|
|
|
261 |
*
|
|
|
262 |
* @deprecated parse_request will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequest instead.
|
|
|
263 |
*/
|
|
|
264 |
function parse_request($message)
|
|
|
265 |
{
|
|
|
266 |
return Message::parseRequest($message);
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
/**
|
|
|
270 |
* Parses a response message string into a response object.
|
|
|
271 |
*
|
|
|
272 |
* @param string $message Response message string.
|
|
|
273 |
*
|
|
|
274 |
* @return Response
|
|
|
275 |
*
|
|
|
276 |
* @deprecated parse_response will be removed in guzzlehttp/psr7:2.0. Use Message::parseResponse instead.
|
|
|
277 |
*/
|
|
|
278 |
function parse_response($message)
|
|
|
279 |
{
|
|
|
280 |
return Message::parseResponse($message);
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
/**
|
|
|
284 |
* Parse a query string into an associative array.
|
|
|
285 |
*
|
|
|
286 |
* If multiple values are found for the same key, the value of that key value
|
|
|
287 |
* pair will become an array. This function does not parse nested PHP style
|
|
|
288 |
* arrays into an associative array (e.g., `foo[a]=1&foo[b]=2` will be parsed
|
|
|
289 |
* into `['foo[a]' => '1', 'foo[b]' => '2'])`.
|
|
|
290 |
*
|
|
|
291 |
* @param string $str Query string to parse
|
|
|
292 |
* @param int|bool $urlEncoding How the query string is encoded
|
|
|
293 |
*
|
|
|
294 |
* @return array
|
|
|
295 |
*
|
|
|
296 |
* @deprecated parse_query will be removed in guzzlehttp/psr7:2.0. Use Query::parse instead.
|
|
|
297 |
*/
|
|
|
298 |
function parse_query($str, $urlEncoding = true)
|
|
|
299 |
{
|
|
|
300 |
return Query::parse($str, $urlEncoding);
|
|
|
301 |
}
|
|
|
302 |
|
|
|
303 |
/**
|
|
|
304 |
* Build a query string from an array of key value pairs.
|
|
|
305 |
*
|
|
|
306 |
* This function can use the return value of `parse_query()` to build a query
|
|
|
307 |
* string. This function does not modify the provided keys when an array is
|
|
|
308 |
* encountered (like `http_build_query()` would).
|
|
|
309 |
*
|
|
|
310 |
* @param array $params Query string parameters.
|
|
|
311 |
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
|
|
|
312 |
* to encode using RFC3986, or PHP_QUERY_RFC1738
|
|
|
313 |
* to encode using RFC1738.
|
|
|
314 |
* @return string
|
|
|
315 |
*
|
|
|
316 |
* @deprecated build_query will be removed in guzzlehttp/psr7:2.0. Use Query::build instead.
|
|
|
317 |
*/
|
|
|
318 |
function build_query(array $params, $encoding = PHP_QUERY_RFC3986)
|
|
|
319 |
{
|
|
|
320 |
return Query::build($params, $encoding);
|
|
|
321 |
}
|
|
|
322 |
|
|
|
323 |
/**
|
|
|
324 |
* Determines the mimetype of a file by looking at its extension.
|
|
|
325 |
*
|
|
|
326 |
* @param string $filename
|
|
|
327 |
*
|
|
|
328 |
* @return string|null
|
|
|
329 |
*
|
|
|
330 |
* @deprecated mimetype_from_filename will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromFilename instead.
|
|
|
331 |
*/
|
|
|
332 |
function mimetype_from_filename($filename)
|
|
|
333 |
{
|
|
|
334 |
return MimeType::fromFilename($filename);
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
/**
|
|
|
338 |
* Maps a file extensions to a mimetype.
|
|
|
339 |
*
|
|
|
340 |
* @param $extension string The file extension.
|
|
|
341 |
*
|
|
|
342 |
* @return string|null
|
|
|
343 |
*
|
|
|
344 |
* @link http://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types
|
|
|
345 |
* @deprecated mimetype_from_extension will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromExtension instead.
|
|
|
346 |
*/
|
|
|
347 |
function mimetype_from_extension($extension)
|
|
|
348 |
{
|
|
|
349 |
return MimeType::fromExtension($extension);
|
|
|
350 |
}
|
|
|
351 |
|
|
|
352 |
/**
|
|
|
353 |
* Parses an HTTP message into an associative array.
|
|
|
354 |
*
|
|
|
355 |
* The array contains the "start-line" key containing the start line of
|
|
|
356 |
* the message, "headers" key containing an associative array of header
|
|
|
357 |
* array values, and a "body" key containing the body of the message.
|
|
|
358 |
*
|
|
|
359 |
* @param string $message HTTP request or response to parse.
|
|
|
360 |
*
|
|
|
361 |
* @return array
|
|
|
362 |
*
|
|
|
363 |
* @internal
|
|
|
364 |
* @deprecated _parse_message will be removed in guzzlehttp/psr7:2.0. Use Message::parseMessage instead.
|
|
|
365 |
*/
|
|
|
366 |
function _parse_message($message)
|
|
|
367 |
{
|
|
|
368 |
return Message::parseMessage($message);
|
|
|
369 |
}
|
|
|
370 |
|
|
|
371 |
/**
|
|
|
372 |
* Constructs a URI for an HTTP request message.
|
|
|
373 |
*
|
|
|
374 |
* @param string $path Path from the start-line
|
|
|
375 |
* @param array $headers Array of headers (each value an array).
|
|
|
376 |
*
|
|
|
377 |
* @return string
|
|
|
378 |
*
|
|
|
379 |
* @internal
|
|
|
380 |
* @deprecated _parse_request_uri will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequestUri instead.
|
|
|
381 |
*/
|
|
|
382 |
function _parse_request_uri($path, array $headers)
|
|
|
383 |
{
|
|
|
384 |
return Message::parseRequestUri($path, $headers);
|
|
|
385 |
}
|
|
|
386 |
|
|
|
387 |
/**
|
|
|
388 |
* Get a short summary of the message body.
|
|
|
389 |
*
|
|
|
390 |
* Will return `null` if the response is not printable.
|
|
|
391 |
*
|
|
|
392 |
* @param MessageInterface $message The message to get the body summary
|
|
|
393 |
* @param int $truncateAt The maximum allowed size of the summary
|
|
|
394 |
*
|
|
|
395 |
* @return string|null
|
|
|
396 |
*
|
|
|
397 |
* @deprecated get_message_body_summary will be removed in guzzlehttp/psr7:2.0. Use Message::bodySummary instead.
|
|
|
398 |
*/
|
|
|
399 |
function get_message_body_summary(MessageInterface $message, $truncateAt = 120)
|
|
|
400 |
{
|
|
|
401 |
return Message::bodySummary($message, $truncateAt);
|
|
|
402 |
}
|
|
|
403 |
|
|
|
404 |
/**
|
|
|
405 |
* Remove the items given by the keys, case insensitively from the data.
|
|
|
406 |
*
|
|
|
407 |
* @param iterable<string> $keys
|
|
|
408 |
*
|
|
|
409 |
* @return array
|
|
|
410 |
*
|
|
|
411 |
* @internal
|
|
|
412 |
* @deprecated _caseless_remove will be removed in guzzlehttp/psr7:2.0. Use Utils::caselessRemove instead.
|
|
|
413 |
*/
|
|
|
414 |
function _caseless_remove($keys, array $data)
|
|
|
415 |
{
|
|
|
416 |
return Utils::caselessRemove($keys, $data);
|
|
|
417 |
}
|