PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.4
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.4
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 19.0 All 129 releases
wordpress-seo / vendor_prefixed / guzzlehttp / promises / src / Create.php

Create.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.4, at vendor_prefixed/guzzlehttp/promises/src/Create.php

72 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace YoastSEO_Vendor\GuzzleHttp\Promise;
5
6 final class Create
7 {
8 /**
9 * Creates a promise for a value if the value is not a promise.
10 *
11 * @param mixed $value Promise or value.
12 */
13 public static function promiseFor($value) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
14 {
15 if ($value instanceof \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface) {
16 return $value;
17 }
18 // Return a Guzzle promise that shadows the given promise.
19 if (\is_object($value) && \method_exists($value, 'then')) {
20 $wfn = \method_exists($value, 'wait') ? [$value, 'wait'] : null;
21 $cfn = \method_exists($value, 'cancel') ? [$value, 'cancel'] : null;
22 $promise = new \YoastSEO_Vendor\GuzzleHttp\Promise\Promise($wfn, $cfn);
23 $value->then([$promise, 'resolve'], [$promise, 'reject']);
24 return $promise;
25 }
26 return new \YoastSEO_Vendor\GuzzleHttp\Promise\FulfilledPromise($value);
27 }
28 /**
29 * Creates a rejected promise for a reason if the reason is not a promise.
30 * If the provided reason is a promise, then it is returned as-is.
31 *
32 * @param mixed $reason Promise or reason.
33 */
34 public static function rejectionFor($reason) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
35 {
36 if ($reason instanceof \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface) {
37 return $reason;
38 }
39 return new \YoastSEO_Vendor\GuzzleHttp\Promise\RejectedPromise($reason);
40 }
41 /**
42 * Create an exception for a rejected promise value.
43 *
44 * @param mixed $reason
45 */
46 public static function exceptionFor($reason) : \Throwable
47 {
48 if ($reason instanceof \Throwable) {
49 return $reason;
50 }
51 return new \YoastSEO_Vendor\GuzzleHttp\Promise\RejectionException($reason);
52 }
53 /**
54 * Returns an iterator for the given value.
55 *
56 * @param mixed $value
57 */
58 public static function iterFor($value) : \Iterator
59 {
60 if ($value instanceof \Iterator) {
61 return $value;
62 }
63 if (\is_array($value)) {
64 return new \ArrayIterator($value);
65 }
66 if (!\is_iterable($value)) {
67 \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/promises', '2.5', 'Passing a non-iterable to %s::%s() is deprecated; guzzlehttp/promises 3.0 will require an iterable.', __CLASS__, __FUNCTION__);
68 }
69 return new \ArrayIterator([$value]);
70 }
71 }
72