1<?php 2 3namespace GuzzleHttp\Psr7; 4 5use Psr\Http\Message\MessageInterface; 6use Psr\Http\Message\RequestInterface; 7use Psr\Http\Message\StreamInterface; 8use 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 */ 19function 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 */ 39function 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|int|float|bool|StreamInterface|callable|\Iterator|null $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 */ 82function 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 */ 99function 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 */ 114function 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 */ 141function 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 */ 158function 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 */ 178function 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 * 191 * @return string 192 * 193 * @throws \RuntimeException on error. 194 * 195 * @deprecated copy_to_string will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToString instead. 196 */ 197function copy_to_string(StreamInterface $stream, $maxLen = -1) 198{ 199 return Utils::copyToString($stream, $maxLen); 200} 201 202/** 203 * Copy the contents of a stream into another stream until the given number 204 * of bytes have been read. 205 * 206 * @param StreamInterface $source Stream to read from 207 * @param StreamInterface $dest Stream to write to 208 * @param int $maxLen Maximum number of bytes to read. Pass -1 209 * to read the entire stream. 210 * 211 * @throws \RuntimeException on error. 212 * 213 * @deprecated copy_to_stream will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToStream instead. 214 */ 215function copy_to_stream(StreamInterface $source, StreamInterface $dest, $maxLen = -1) 216{ 217 return Utils::copyToStream($source, $dest, $maxLen); 218} 219 220/** 221 * Calculate a hash of a stream. 222 * 223 * This method reads the entire stream to calculate a rolling hash, based on 224 * PHP's `hash_init` functions. 225 * 226 * @param StreamInterface $stream Stream to calculate the hash for 227 * @param string $algo Hash algorithm (e.g. md5, crc32, etc) 228 * @param bool $rawOutput Whether or not to use raw output 229 * 230 * @return string Returns the hash of the stream 231 * 232 * @throws \RuntimeException on error. 233 * 234 * @deprecated hash will be removed in guzzlehttp/psr7:2.0. Use Utils::hash instead. 235 */ 236function hash(StreamInterface $stream, $algo, $rawOutput = false) 237{ 238 return Utils::hash($stream, $algo, $rawOutput); 239} 240 241/** 242 * Read a line from the stream up to the maximum allowed buffer length. 243 * 244 * @param StreamInterface $stream Stream to read from 245 * @param int|null $maxLength Maximum buffer length 246 * 247 * @return string 248 * 249 * @deprecated readline will be removed in guzzlehttp/psr7:2.0. Use Utils::readLine instead. 250 */ 251function readline(StreamInterface $stream, $maxLength = null) 252{ 253 return Utils::readLine($stream, $maxLength); 254} 255 256/** 257 * Parses a request message string into a request object. 258 * 259 * @param string $message Request message string. 260 * 261 * @return Request 262 * 263 * @deprecated parse_request will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequest instead. 264 */ 265function parse_request($message) 266{ 267 return Message::parseRequest($message); 268} 269 270/** 271 * Parses a response message string into a response object. 272 * 273 * @param string $message Response message string. 274 * 275 * @return Response 276 * 277 * @deprecated parse_response will be removed in guzzlehttp/psr7:2.0. Use Message::parseResponse instead. 278 */ 279function parse_response($message) 280{ 281 return Message::parseResponse($message); 282} 283 284/** 285 * Parse a query string into an associative array. 286 * 287 * If multiple values are found for the same key, the value of that key value 288 * pair will become an array. This function does not parse nested PHP style 289 * arrays into an associative array (e.g., `foo[a]=1&foo[b]=2` will be parsed 290 * into `['foo[a]' => '1', 'foo[b]' => '2'])`. 291 * 292 * @param string $str Query string to parse 293 * @param int|bool $urlEncoding How the query string is encoded 294 * 295 * @return array 296 * 297 * @deprecated parse_query will be removed in guzzlehttp/psr7:2.0. Use Query::parse instead. 298 */ 299function parse_query($str, $urlEncoding = true) 300{ 301 return Query::parse($str, $urlEncoding); 302} 303 304/** 305 * Build a query string from an array of key value pairs. 306 * 307 * This function can use the return value of `parse_query()` to build a query 308 * string. This function does not modify the provided keys when an array is 309 * encountered (like `http_build_query()` would). 310 * 311 * @param array $params Query string parameters. 312 * @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986 313 * to encode using RFC3986, or PHP_QUERY_RFC1738 314 * to encode using RFC1738. 315 * 316 * @return string 317 * 318 * @deprecated build_query will be removed in guzzlehttp/psr7:2.0. Use Query::build instead. 319 */ 320function build_query(array $params, $encoding = PHP_QUERY_RFC3986) 321{ 322 return Query::build($params, $encoding); 323} 324 325/** 326 * Determines the mimetype of a file by looking at its extension. 327 * 328 * @param string $filename 329 * 330 * @return string|null 331 * 332 * @deprecated mimetype_from_filename will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromFilename instead. 333 */ 334function mimetype_from_filename($filename) 335{ 336 return MimeType::fromFilename($filename); 337} 338 339/** 340 * Maps a file extensions to a mimetype. 341 * 342 * @param $extension string The file extension. 343 * 344 * @return string|null 345 * 346 * @link http://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types 347 * @deprecated mimetype_from_extension will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromExtension instead. 348 */ 349function mimetype_from_extension($extension) 350{ 351 return MimeType::fromExtension($extension); 352} 353 354/** 355 * Parses an HTTP message into an associative array. 356 * 357 * The array contains the "start-line" key containing the start line of 358 * the message, "headers" key containing an associative array of header 359 * array values, and a "body" key containing the body of the message. 360 * 361 * @param string $message HTTP request or response to parse. 362 * 363 * @return array 364 * 365 * @internal 366 * 367 * @deprecated _parse_message will be removed in guzzlehttp/psr7:2.0. Use Message::parseMessage instead. 368 */ 369function _parse_message($message) 370{ 371 return Message::parseMessage($message); 372} 373 374/** 375 * Constructs a URI for an HTTP request message. 376 * 377 * @param string $path Path from the start-line 378 * @param array $headers Array of headers (each value an array). 379 * 380 * @return string 381 * 382 * @internal 383 * 384 * @deprecated _parse_request_uri will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequestUri instead. 385 */ 386function _parse_request_uri($path, array $headers) 387{ 388 return Message::parseRequestUri($path, $headers); 389} 390 391/** 392 * Get a short summary of the message body. 393 * 394 * Will return `null` if the response is not printable. 395 * 396 * @param MessageInterface $message The message to get the body summary 397 * @param int $truncateAt The maximum allowed size of the summary 398 * 399 * @return string|null 400 * 401 * @deprecated get_message_body_summary will be removed in guzzlehttp/psr7:2.0. Use Message::bodySummary instead. 402 */ 403function get_message_body_summary(MessageInterface $message, $truncateAt = 120) 404{ 405 return Message::bodySummary($message, $truncateAt); 406} 407 408/** 409 * Remove the items given by the keys, case insensitively from the data. 410 * 411 * @param iterable<string> $keys 412 * 413 * @return array 414 * 415 * @internal 416 * 417 * @deprecated _caseless_remove will be removed in guzzlehttp/psr7:2.0. Use Utils::caselessRemove instead. 418 */ 419function _caseless_remove($keys, array $data) 420{ 421 return Utils::caselessRemove($keys, $data); 422} 423