PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.6 28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 All 130 releases
← All changes | vendor_prefixed/guzzlehttp/guzzle/src/functions.php +76 -131 19.0 → trunk View file →
@@ -1,43 +1,22 @@
1 1 <?php
2 2
3 3 namespace YoastSEO_Vendor\GuzzleHttp;
4 4
5 -use YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler;
6 -use YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler;
7 -use YoastSEO_Vendor\GuzzleHttp\Handler\Proxy;
8 -use YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler;
9 5 /**
10 - * Expands a URI template
11 - *
12 - * @param string $template URI template
13 - * @param array $variables Template variables
14 - *
15 - * @return string
16 - */
17 -function uri_template($template, array $variables)
18 -{
19 - if (\extension_loaded('uri_template')) {
20 - // @codeCoverageIgnoreStart
21 - return \YoastSEO_Vendor\uri_template($template, $variables);
22 - // @codeCoverageIgnoreEnd
23 - }
24 - static $uriTemplate;
25 - if (!$uriTemplate) {
26 - $uriTemplate = new \YoastSEO_Vendor\GuzzleHttp\UriTemplate();
27 - }
28 - return $uriTemplate->expand($template, $variables);
29 -}
30 -/**
31 6 * Debug function used to describe the provided value type and class.
32 7 *
33 - * @param mixed $input
8 + * @param mixed $input Any type of variable to describe the type of. This
9 + * parameter misses a typehint because of that.
34 10 *
35 11 * @return string Returns a string containing the type of the variable and
36 12 * if a class is provided, the class name.
13 + *
14 + * @deprecated describe_type will be removed in guzzlehttp/guzzle:8.0. Use get_debug_type() instead.
37 15 */
38 -function describe_type($input)
16 +function describe_type($input) : string
39 17 {
18 + \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/guzzle', '7.1', '%s() is deprecated and will be removed in 8.0. Use get_debug_type() instead.', __FUNCTION__);
40 19 switch (\gettype($input)) {
41 20 case 'object':
42 21 return 'object(' . \get_class($input) . ')';
43 22 case 'array':
@@ -45,9 +24,11 @@
45 24 default:
46 25 \ob_start();
47 26 \var_dump($input);
48 27 // normalize float vs double
49 - return \str_replace('double(', 'float(', \rtrim(\ob_get_clean()));
28 + /** @var string $varDumpContent */
29 + $varDumpContent = \ob_get_clean();
30 + return \str_replace('double(', 'float(', \rtrim($varDumpContent, " \n\r\t\x00\v"));
50 31 }
51 32 }
52 33 /**
53 34 * Parses an array of header lines into an associative array of headers.
@@ -52,19 +33,16 @@
52 33 /**
53 34 * Parses an array of header lines into an associative array of headers.
54 35 *
55 36 * @param iterable $lines Header lines array of strings in the following
56 - * format: "Name: Value"
57 - * @return array
37 + * format: "Name: Value"
38 + *
39 + * @deprecated headers_from_lines will be removed in guzzlehttp/guzzle:8.0. Use Utils::headersFromLines instead.
58 40 */
59 -function headers_from_lines($lines)
41 +function headers_from_lines(iterable $lines) : array
60 42 {
61 - $headers = [];
62 - foreach ($lines as $line) {
63 - $parts = \explode(':', $line, 2);
64 - $headers[\trim($parts[0])][] = isset($parts[1]) ? \trim($parts[1]) : null;
65 - }
66 - return $headers;
43 + \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/guzzle', '7.1', '%s() is deprecated and will be removed in 8.0. Use Utils::headersFromLines() instead.', __FUNCTION__);
44 + return \YoastSEO_Vendor\GuzzleHttp\Utils::headersFromLines($lines);
67 45 }
68 46 /**
69 47 * Returns a debug stream based on the provided variable.
70 48 *
@@ -70,17 +48,15 @@
70 48 *
71 49 * @param mixed $value Optional value
72 50 *
73 51 * @return resource
52 + *
53 + * @deprecated debug_resource will be removed in guzzlehttp/guzzle:8.0. Use Utils::debugResource instead.
74 54 */
75 55 function debug_resource($value = null)
76 56 {
77 - if (\is_resource($value)) {
78 - return $value;
79 - } elseif (\defined('STDOUT')) {
80 - return \STDOUT;
81 - }
82 - return \fopen('php://output', 'w');
57 + \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/guzzle', '7.1', '%s() is deprecated and will be removed in 8.0. Use Utils::debugResource() instead.', __FUNCTION__);
58 + return \YoastSEO_Vendor\GuzzleHttp\Utils::debugResource($value);
83 59 }
84 60 /**
85 61 * Chooses and creates a default handler to use based on the environment.
86 62 *
@@ -85,44 +61,28 @@
85 61 * Chooses and creates a default handler to use based on the environment.
86 62 *
87 63 * The returned handler is not wrapped by any default middlewares.
88 64 *
89 - * @return callable Returns the best handler for the given system.
65 + * @return callable(\Psr\Http\Message\RequestInterface, array): Promise\PromiseInterface Returns the best handler for the given system.
66 + *
90 67 * @throws \RuntimeException if no viable Handler is available.
68 + *
69 + * @deprecated choose_handler will be removed in guzzlehttp/guzzle:8.0. Use Utils::chooseHandler instead.
91 70 */
92 -function choose_handler()
71 +function choose_handler() : callable
93 72 {
94 - $handler = null;
95 - if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) {
96 - $handler = \YoastSEO_Vendor\GuzzleHttp\Handler\Proxy::wrapSync(new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler(), new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler());
97 - } elseif (\function_exists('curl_exec')) {
98 - $handler = new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler();
99 - } elseif (\function_exists('curl_multi_exec')) {
100 - $handler = new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler();
101 - }
102 - if (\ini_get('allow_url_fopen')) {
103 - $handler = $handler ? \YoastSEO_Vendor\GuzzleHttp\Handler\Proxy::wrapStreaming($handler, new \YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler()) : new \YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler();
104 - } elseif (!$handler) {
105 - throw new \RuntimeException('GuzzleHttp requires cURL, the ' . 'allow_url_fopen ini setting, or a custom HTTP handler.');
106 - }
107 - return $handler;
73 + \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/guzzle', '7.1', '%s() is deprecated and will be removed in 8.0. Use Utils::chooseHandler() instead.', __FUNCTION__);
74 + return \YoastSEO_Vendor\GuzzleHttp\Utils::chooseHandler();
108 75 }
109 76 /**
110 - * Get the default User-Agent string to use with Guzzle
77 + * Get the default User-Agent string to use with Guzzle.
111 78 *
112 - * @return string
79 + * @deprecated default_user_agent will be removed in guzzlehttp/guzzle:8.0. Use Utils::defaultUserAgent instead.
113 80 */
114 -function default_user_agent()
81 +function default_user_agent() : string
115 82 {
116 - static $defaultAgent = '';
117 - if (!$defaultAgent) {
118 - $defaultAgent = 'GuzzleHttp/' . \YoastSEO_Vendor\GuzzleHttp\Client::VERSION;
119 - if (\extension_loaded('curl') && \function_exists('curl_version')) {
120 - $defaultAgent .= ' curl/' . \curl_version()['version'];
121 - }
122 - $defaultAgent .= ' PHP/' . \PHP_VERSION;
123 - }
124 - return $defaultAgent;
83 + \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/guzzle', '7.1', '%s() is deprecated and will be removed in 8.0. Use Utils::defaultUserAgent() instead.', __FUNCTION__);
84 + return \YoastSEO_Vendor\GuzzleHttp\Utils::defaultUserAgent();
125 85 }
126 86 /**
127 87 * Returns the default cacert bundle for the current system.
128 88 *
@@ -133,13 +93,15 @@
133 93 * disk, they will be utilized.
134 94 *
135 95 * Note: the result of this function is cached for subsequent calls.
136 96 *
137 - * @return string
138 97 * @throws \RuntimeException if no bundle can be found.
98 + *
99 + * @deprecated default_ca_bundle will be removed in guzzlehttp/guzzle:8.0. This function is not needed in PHP 5.6+.
139 100 */
140 -function default_ca_bundle()
101 +function default_ca_bundle() : string
141 102 {
103 + \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/guzzle', '7.1', '%s() is deprecated and will be removed in 8.0. This function is not needed in PHP 5.6+.', __FUNCTION__);
142 104 static $cached = null;
143 105 static $cafiles = [
144 106 // Red Hat, CentOS, Fedora (provided by the ca-certificates package)
145 107 '/etc/pki/tls/certs/ca-bundle.crt',
@@ -174,17 +136,16 @@
174 136 throw new \RuntimeException(<<<EOT
175 137 No system CA bundle could be found in any of the the common system locations.
176 138 PHP versions earlier than 5.6 are not properly configured to use the system's
177 139 CA bundle by default. In order to verify peer certificates, you will need to
178 -supply the path on disk to a certificate bundle to the 'verify' request
179 -option: http://docs.guzzlephp.org/en/latest/clients.html#verify. If you do not
180 -need a specific certificate bundle, then Mozilla provides a commonly used CA
181 -bundle which can be downloaded here (provided by the maintainer of cURL):
182 -https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt. Once
183 -you have a CA bundle available on disk, you can set the 'openssl.cafile' PHP
184 -ini setting to point to the path to the file, allowing you to omit the 'verify'
185 -request option. See http://curl.haxx.se/docs/sslcerts.html for more
186 -information.
140 +supply the path on disk to a certificate bundle to the 'verify' request option:
141 +https://github.com/guzzle/guzzle/blob/7.15/docs/request-options.md#verify. If
142 +you do not need a specific certificate bundle, then Mozilla provides a commonly
143 +used CA bundle which can be downloaded here (provided by the maintainer of
144 +cURL): https://curl.se/ca/cacert.pem. Once you have a CA bundle available on
145 +disk, you can set the 'openssl.cafile' PHP ini setting to point to the path to
146 +the file, allowing you to omit the 'verify' request option. See
147 +https://curl.se/docs/sslcerts.html for more information.
187 148 EOT
188 149 );
189 150 }
190 151 /**
@@ -190,19 +151,14 @@
190 151 /**
191 152 * Creates an associative array of lowercase header names to the actual
192 153 * header casing.
193 154 *
194 - * @param array $headers
195 - *
196 - * @return array
155 + * @deprecated normalize_header_keys will be removed in guzzlehttp/guzzle:8.0. Use Utils::normalizeHeaderKeys instead.
197 156 */
198 -function normalize_header_keys(array $headers)
157 +function normalize_header_keys(array $headers) : array
199 158 {
200 - $result = [];
201 - foreach (\array_keys($headers) as $key) {
202 - $result[\strtolower($key)] = $key;
203 - }
204 - return $result;
159 + \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/guzzle', '7.1', '%s() is deprecated and will be removed in 8.0. Use Utils::normalizeHeaderKeys() instead.', __FUNCTION__);
160 + return \YoastSEO_Vendor\GuzzleHttp\Utils::normalizeHeaderKeys($headers);
205 161 }
206 162 /**
207 163 * Returns true if the provided host matches any of the no proxy areas.
208 164 *
@@ -216,62 +172,47 @@
216 172 * 2. An exact match.
217 173 * 3. The area starts with "." and the area is the last part of the host. e.g.
218 174 * '.mit.edu' will match any host that ends with '.mit.edu'.
219 175 *
220 - * @param string $host Host to check against the patterns.
221 - * @param array $noProxyArray An array of host patterns.
176 + * @param string $host Host to check against the patterns.
177 + * @param string[] $noProxyArray An array of host patterns.
222 178 *
223 - * @return bool
179 + * @throws Exception\InvalidArgumentException
180 + *
181 + * @deprecated is_host_in_noproxy will be removed in guzzlehttp/guzzle:8.0. Use Utils::isHostInNoProxy instead.
224 182 */
225 -function is_host_in_noproxy($host, array $noProxyArray)
183 +function is_host_in_noproxy(string $host, array $noProxyArray) : bool
226 184 {
227 - if (\strlen($host) === 0) {
228 - throw new \InvalidArgumentException('Empty host provided');
229 - }
230 - // Strip port if present.
231 - if (\strpos($host, ':')) {
232 - $host = \explode($host, ':', 2)[0];
233 - }
234 - foreach ($noProxyArray as $area) {
235 - // Always match on wildcards.
236 - if ($area === '*') {
237 - return \true;
238 - } elseif (empty($area)) {
239 - // Don't match on empty values.
240 - continue;
241 - } elseif ($area === $host) {
242 - // Exact matches.
243 - return \true;
244 - } else {
245 - // Special match if the area when prefixed with ".". Remove any
246 - // existing leading "." and add a new leading ".".
247 - $area = '.' . \ltrim($area, '.');
248 - if (\substr($host, -\strlen($area)) === $area) {
249 - return \true;
250 - }
251 - }
252 - }
253 - return \false;
185 + \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/guzzle', '7.1', '%s() is deprecated and will be removed in 8.0. Use Utils::isHostInNoProxy() instead.', __FUNCTION__);
186 + return \YoastSEO_Vendor\GuzzleHttp\Utils::isHostInNoProxy($host, $noProxyArray);
254 187 }
255 188 /**
256 189 * Wrapper for json_decode that throws when an error occurs.
257 190 *
258 191 * @param string $json JSON data to parse
259 - * @param bool $assoc When true, returned objects will be converted
192 + * @param bool $assoc When true, returned objects will be converted
260 193 * into associative arrays.
261 194 * @param int $depth User specified recursion depth.
262 195 * @param int $options Bitmask of JSON decode options.
263 196 *
264 - * @return mixed
197 + * @return object|array|string|int|float|bool|null
198 + *
265 199 * @throws Exception\InvalidArgumentException if the JSON cannot be decoded.
266 - * @link http://www.php.net/manual/en/function.json-decode.php
200 + *
201 + * @see https://www.php.net/manual/en/function.json-decode.php
202 + * @deprecated json_decode will be removed in guzzlehttp/guzzle:8.0. Use PHP's json_decode() instead.
267 203 */
268 -function json_decode($json, $assoc = \false, $depth = 512, $options = 0)
204 +function json_decode(string $json, bool $assoc = \false, int $depth = 512, int $options = 0)
269 205 {
206 + \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/guzzle', '7.1', '%s() is deprecated and will be removed in 8.0. Use PHP\'s json_decode() instead.', __FUNCTION__);
207 + if ($depth < 1) {
208 + throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_decode error: Maximum stack depth exceeded');
209 + }
270 210 $data = \json_decode($json, $assoc, $depth, $options);
271 211 if (\JSON_ERROR_NONE !== \json_last_error()) {
272 212 throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_decode error: ' . \json_last_error_msg());
273 213 }
214 + /** @var object|array|string|int|float|bool|null $data */
274 215 return $data;
275 216 }
276 217 /**
277 218 * Wrapper for JSON encoding that throws when an error occurs.
@@ -276,19 +217,23 @@
276 217 /**
277 218 * Wrapper for JSON encoding that throws when an error occurs.
278 219 *
279 220 * @param mixed $value The value being encoded
280 - * @param int $options JSON encode option bitmask
281 - * @param int $depth Set the maximum depth. Must be greater than zero.
221 + * @param int $options JSON encode option bitmask
222 + * @param int $depth Set the maximum depth. Must be greater than zero.
282 223 *
283 - * @return string
284 224 * @throws Exception\InvalidArgumentException if the JSON cannot be encoded.
285 - * @link http://www.php.net/manual/en/function.json-encode.php
225 + *
226 + * @see https://www.php.net/manual/en/function.json-encode.php
227 + * @deprecated json_encode will be removed in guzzlehttp/guzzle:8.0. Use PHP's json_encode() instead.
286 228 */
287 -function json_encode($value, $options = 0, $depth = 512)
229 +function json_encode($value, int $options = 0, int $depth = 512) : string
288 230 {
231 + \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/guzzle', '7.1', '%s() is deprecated and will be removed in 8.0. Use PHP\'s json_encode() instead.', __FUNCTION__);
232 + /** @var positive-int $depth */
289 233 $json = \json_encode($value, $options, $depth);
290 234 if (\JSON_ERROR_NONE !== \json_last_error()) {
291 235 throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_encode error: ' . \json_last_error_msg());
292 236 }
237 + /** @var non-empty-string $json */
293 238 return $json;
294 239 }