functions.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace GuzzleHttp;
  3. /**
  4. * Debug function used to describe the provided value type and class.
  5. *
  6. * @param mixed $input Any type of variable to describe the type of. This
  7. * parameter misses a typehint because of that.
  8. *
  9. * @return string Returns a string containing the type of the variable and
  10. * if a class is provided, the class name.
  11. *
  12. * @deprecated describe_type will be removed in guzzlehttp/guzzle:8.0. Use Utils::describeType instead.
  13. */
  14. function describe_type($input): string
  15. {
  16. return Utils::describeType($input);
  17. }
  18. /**
  19. * Parses an array of header lines into an associative array of headers.
  20. *
  21. * @param iterable $lines Header lines array of strings in the following
  22. * format: "Name: Value"
  23. *
  24. * @deprecated headers_from_lines will be removed in guzzlehttp/guzzle:8.0. Use Utils::headersFromLines instead.
  25. */
  26. function headers_from_lines(iterable $lines): array
  27. {
  28. return Utils::headersFromLines($lines);
  29. }
  30. /**
  31. * Returns a debug stream based on the provided variable.
  32. *
  33. * @param mixed $value Optional value
  34. *
  35. * @return resource
  36. *
  37. * @deprecated debug_resource will be removed in guzzlehttp/guzzle:8.0. Use Utils::debugResource instead.
  38. */
  39. function debug_resource($value = null)
  40. {
  41. return Utils::debugResource($value);
  42. }
  43. /**
  44. * Chooses and creates a default handler to use based on the environment.
  45. *
  46. * The returned handler is not wrapped by any default middlewares.
  47. *
  48. * @throws \RuntimeException if no viable Handler is available.
  49. *
  50. * @return callable(\Psr\Http\Message\RequestInterface, array): \GuzzleHttp\Promise\PromiseInterface Returns the best handler for the given system.
  51. *
  52. * @deprecated choose_handler will be removed in guzzlehttp/guzzle:8.0. Use Utils::chooseHandler instead.
  53. */
  54. function choose_handler(): callable
  55. {
  56. return Utils::chooseHandler();
  57. }
  58. /**
  59. * Get the default User-Agent string to use with Guzzle.
  60. *
  61. * @deprecated default_user_agent will be removed in guzzlehttp/guzzle:8.0. Use Utils::defaultUserAgent instead.
  62. */
  63. function default_user_agent(): string
  64. {
  65. return Utils::defaultUserAgent();
  66. }
  67. /**
  68. * Returns the default cacert bundle for the current system.
  69. *
  70. * First, the openssl.cafile and curl.cainfo php.ini settings are checked.
  71. * If those settings are not configured, then the common locations for
  72. * bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X
  73. * and Windows are checked. If any of these file locations are found on
  74. * disk, they will be utilized.
  75. *
  76. * Note: the result of this function is cached for subsequent calls.
  77. *
  78. * @throws \RuntimeException if no bundle can be found.
  79. *
  80. * @deprecated default_ca_bundle will be removed in guzzlehttp/guzzle:8.0. This function is not needed in PHP 5.6+.
  81. */
  82. function default_ca_bundle(): string
  83. {
  84. return Utils::defaultCaBundle();
  85. }
  86. /**
  87. * Creates an associative array of lowercase header names to the actual
  88. * header casing.
  89. *
  90. * @deprecated normalize_header_keys will be removed in guzzlehttp/guzzle:8.0. Use Utils::normalizeHeaderKeys instead.
  91. */
  92. function normalize_header_keys(array $headers): array
  93. {
  94. return Utils::normalizeHeaderKeys($headers);
  95. }
  96. /**
  97. * Returns true if the provided host matches any of the no proxy areas.
  98. *
  99. * This method will strip a port from the host if it is present. Each pattern
  100. * can be matched with an exact match (e.g., "foo.com" == "foo.com") or a
  101. * partial match: (e.g., "foo.com" == "baz.foo.com" and ".foo.com" ==
  102. * "baz.foo.com", but ".foo.com" != "foo.com").
  103. *
  104. * Areas are matched in the following cases:
  105. * 1. "*" (without quotes) always matches any hosts.
  106. * 2. An exact match.
  107. * 3. The area starts with "." and the area is the last part of the host. e.g.
  108. * '.mit.edu' will match any host that ends with '.mit.edu'.
  109. *
  110. * @param string $host Host to check against the patterns.
  111. * @param string[] $noProxyArray An array of host patterns.
  112. *
  113. * @throws Exception\InvalidArgumentException
  114. *
  115. * @deprecated is_host_in_noproxy will be removed in guzzlehttp/guzzle:8.0. Use Utils::isHostInNoProxy instead.
  116. */
  117. function is_host_in_noproxy(string $host, array $noProxyArray): bool
  118. {
  119. return Utils::isHostInNoProxy($host, $noProxyArray);
  120. }
  121. /**
  122. * Wrapper for json_decode that throws when an error occurs.
  123. *
  124. * @param string $json JSON data to parse
  125. * @param bool $assoc When true, returned objects will be converted
  126. * into associative arrays.
  127. * @param int $depth User specified recursion depth.
  128. * @param int $options Bitmask of JSON decode options.
  129. *
  130. * @return object|array|string|int|float|bool|null
  131. *
  132. * @throws Exception\InvalidArgumentException if the JSON cannot be decoded.
  133. *
  134. * @link https://www.php.net/manual/en/function.json-decode.php
  135. * @deprecated json_decode will be removed in guzzlehttp/guzzle:8.0. Use Utils::jsonDecode instead.
  136. */
  137. function json_decode(string $json, bool $assoc = false, int $depth = 512, int $options = 0)
  138. {
  139. return Utils::jsonDecode($json, $assoc, $depth, $options);
  140. }
  141. /**
  142. * Wrapper for JSON encoding that throws when an error occurs.
  143. *
  144. * @param mixed $value The value being encoded
  145. * @param int $options JSON encode option bitmask
  146. * @param int $depth Set the maximum depth. Must be greater than zero.
  147. *
  148. * @throws Exception\InvalidArgumentException if the JSON cannot be encoded.
  149. *
  150. * @link https://www.php.net/manual/en/function.json-encode.php
  151. * @deprecated json_encode will be removed in guzzlehttp/guzzle:8.0. Use Utils::jsonEncode instead.
  152. */
  153. function json_encode($value, int $options = 0, int $depth = 512): string
  154. {
  155. return Utils::jsonEncode($value, $options, $depth);
  156. }