PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 19.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v19.0
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 19.0, at vendor_prefixed/guzzlehttp/promises/src/Create.php

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