PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 3.7.0
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v3.7.0
0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / vendor_prefixed / guzzlehttp / guzzle / src / functions.php
wp-mail-smtp / vendor_prefixed / guzzlehttp / guzzle / src Last commit date
Cookie 3 years ago Exception 3 years ago Handler 3 years ago Client.php 3 years ago ClientInterface.php 3 years ago HandlerStack.php 3 years ago MessageFormatter.php 3 years ago Middleware.php 3 years ago Pool.php 3 years ago PrepareBodyMiddleware.php 3 years ago RedirectMiddleware.php 3 years ago RequestOptions.php 3 years ago RetryMiddleware.php 3 years ago TransferStats.php 3 years ago UriTemplate.php 3 years ago Utils.php 3 years ago functions.php 3 years ago functions_include.php 3 years ago
functions.php
295 lines
1 <?php
2
3 namespace WPMailSMTP\Vendor\GuzzleHttp;
4
5 use WPMailSMTP\Vendor\GuzzleHttp\Handler\CurlHandler;
6 use WPMailSMTP\Vendor\GuzzleHttp\Handler\CurlMultiHandler;
7 use WPMailSMTP\Vendor\GuzzleHttp\Handler\Proxy;
8 use WPMailSMTP\Vendor\GuzzleHttp\Handler\StreamHandler;
9 /**
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 \WPMailSMTP\Vendor\uri_template($template, $variables);
22 // @codeCoverageIgnoreEnd
23 }
24 static $uriTemplate;
25 if (!$uriTemplate) {
26 $uriTemplate = new \WPMailSMTP\Vendor\GuzzleHttp\UriTemplate();
27 }
28 return $uriTemplate->expand($template, $variables);
29 }
30 /**
31 * Debug function used to describe the provided value type and class.
32 *
33 * @param mixed $input
34 *
35 * @return string Returns a string containing the type of the variable and
36 * if a class is provided, the class name.
37 */
38 function describe_type($input)
39 {
40 switch (\gettype($input)) {
41 case 'object':
42 return 'object(' . \get_class($input) . ')';
43 case 'array':
44 return 'array(' . \count($input) . ')';
45 default:
46 \ob_start();
47 \var_dump($input);
48 // normalize float vs double
49 return \str_replace('double(', 'float(', \rtrim(\ob_get_clean()));
50 }
51 }
52 /**
53 * Parses an array of header lines into an associative array of headers.
54 *
55 * @param iterable $lines Header lines array of strings in the following
56 * format: "Name: Value"
57 * @return array
58 */
59 function headers_from_lines($lines)
60 {
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;
67 }
68 /**
69 * Returns a debug stream based on the provided variable.
70 *
71 * @param mixed $value Optional value
72 *
73 * @return resource
74 */
75 function debug_resource($value = null)
76 {
77 if (\is_resource($value)) {
78 return $value;
79 } elseif (\defined('STDOUT')) {
80 return \STDOUT;
81 }
82 return \fopen('php://output', 'w');
83 }
84 /**
85 * Chooses and creates a default handler to use based on the environment.
86 *
87 * The returned handler is not wrapped by any default middlewares.
88 *
89 * @return callable Returns the best handler for the given system.
90 * @throws \RuntimeException if no viable Handler is available.
91 */
92 function choose_handler()
93 {
94 $handler = null;
95 if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) {
96 $handler = \WPMailSMTP\Vendor\GuzzleHttp\Handler\Proxy::wrapSync(new \WPMailSMTP\Vendor\GuzzleHttp\Handler\CurlMultiHandler(), new \WPMailSMTP\Vendor\GuzzleHttp\Handler\CurlHandler());
97 } elseif (\function_exists('curl_exec')) {
98 $handler = new \WPMailSMTP\Vendor\GuzzleHttp\Handler\CurlHandler();
99 } elseif (\function_exists('curl_multi_exec')) {
100 $handler = new \WPMailSMTP\Vendor\GuzzleHttp\Handler\CurlMultiHandler();
101 }
102 if (\ini_get('allow_url_fopen')) {
103 $handler = $handler ? \WPMailSMTP\Vendor\GuzzleHttp\Handler\Proxy::wrapStreaming($handler, new \WPMailSMTP\Vendor\GuzzleHttp\Handler\StreamHandler()) : new \WPMailSMTP\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;
108 }
109 /**
110 * Get the default User-Agent string to use with Guzzle
111 *
112 * @return string
113 */
114 function default_user_agent()
115 {
116 static $defaultAgent = '';
117 if (!$defaultAgent) {
118 $defaultAgent = 'GuzzleHttp/' . \WPMailSMTP\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;
125 }
126 /**
127 * Returns the default cacert bundle for the current system.
128 *
129 * First, the openssl.cafile and curl.cainfo php.ini settings are checked.
130 * If those settings are not configured, then the common locations for
131 * bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X
132 * and Windows are checked. If any of these file locations are found on
133 * disk, they will be utilized.
134 *
135 * Note: the result of this function is cached for subsequent calls.
136 *
137 * @return string
138 * @throws \RuntimeException if no bundle can be found.
139 */
140 function default_ca_bundle()
141 {
142 static $cached = null;
143 static $cafiles = [
144 // Red Hat, CentOS, Fedora (provided by the ca-certificates package)
145 '/etc/pki/tls/certs/ca-bundle.crt',
146 // Ubuntu, Debian (provided by the ca-certificates package)
147 '/etc/ssl/certs/ca-certificates.crt',
148 // FreeBSD (provided by the ca_root_nss package)
149 '/usr/local/share/certs/ca-root-nss.crt',
150 // SLES 12 (provided by the ca-certificates package)
151 '/var/lib/ca-certificates/ca-bundle.pem',
152 // OS X provided by homebrew (using the default path)
153 '/usr/local/etc/openssl/cert.pem',
154 // Google app engine
155 '/etc/ca-certificates.crt',
156 // Windows?
157 'C:\\windows\\system32\\curl-ca-bundle.crt',
158 'C:\\windows\\curl-ca-bundle.crt',
159 ];
160 if ($cached) {
161 return $cached;
162 }
163 if ($ca = \ini_get('openssl.cafile')) {
164 return $cached = $ca;
165 }
166 if ($ca = \ini_get('curl.cainfo')) {
167 return $cached = $ca;
168 }
169 foreach ($cafiles as $filename) {
170 if (\file_exists($filename)) {
171 return $cached = $filename;
172 }
173 }
174 throw new \RuntimeException(<<<EOT
175 No system CA bundle could be found in any of the the common system locations.
176 PHP versions earlier than 5.6 are not properly configured to use the system's
177 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.
187 EOT
188 );
189 }
190 /**
191 * Creates an associative array of lowercase header names to the actual
192 * header casing.
193 *
194 * @param array $headers
195 *
196 * @return array
197 */
198 function normalize_header_keys(array $headers)
199 {
200 $result = [];
201 foreach (\array_keys($headers) as $key) {
202 $result[\strtolower($key)] = $key;
203 }
204 return $result;
205 }
206 /**
207 * Returns true if the provided host matches any of the no proxy areas.
208 *
209 * This method will strip a port from the host if it is present. Each pattern
210 * can be matched with an exact match (e.g., "foo.com" == "foo.com") or a
211 * partial match: (e.g., "foo.com" == "baz.foo.com" and ".foo.com" ==
212 * "baz.foo.com", but ".foo.com" != "foo.com").
213 *
214 * Areas are matched in the following cases:
215 * 1. "*" (without quotes) always matches any hosts.
216 * 2. An exact match.
217 * 3. The area starts with "." and the area is the last part of the host. e.g.
218 * '.mit.edu' will match any host that ends with '.mit.edu'.
219 *
220 * @param string $host Host to check against the patterns.
221 * @param array $noProxyArray An array of host patterns.
222 *
223 * @return bool
224 */
225 function is_host_in_noproxy($host, array $noProxyArray)
226 {
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;
254 }
255 /**
256 * Wrapper for json_decode that throws when an error occurs.
257 *
258 * @param string $json JSON data to parse
259 * @param bool $assoc When true, returned objects will be converted
260 * into associative arrays.
261 * @param int $depth User specified recursion depth.
262 * @param int $options Bitmask of JSON decode options.
263 *
264 * @return mixed
265 * @throws Exception\InvalidArgumentException if the JSON cannot be decoded.
266 * @link http://www.php.net/manual/en/function.json-decode.php
267 */
268 function json_decode($json, $assoc = \false, $depth = 512, $options = 0)
269 {
270 $data = \json_decode($json, $assoc, $depth, $options);
271 if (\JSON_ERROR_NONE !== \json_last_error()) {
272 throw new \WPMailSMTP\Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_decode error: ' . \json_last_error_msg());
273 }
274 return $data;
275 }
276 /**
277 * Wrapper for JSON encoding that throws when an error occurs.
278 *
279 * @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.
282 *
283 * @return string
284 * @throws Exception\InvalidArgumentException if the JSON cannot be encoded.
285 * @link http://www.php.net/manual/en/function.json-encode.php
286 */
287 function json_encode($value, $options = 0, $depth = 512)
288 {
289 $json = \json_encode($value, $options, $depth);
290 if (\JSON_ERROR_NONE !== \json_last_error()) {
291 throw new \WPMailSMTP\Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_encode error: ' . \json_last_error_msg());
292 }
293 return $json;
294 }
295