PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / vendor / _scoped / guzzlehttp / promises / src / Create.php

Create.php in Metricool – Social media and site statistics 2.1.1, at vendor/_scoped/guzzlehttp/promises/src/Create.php

72 lines 2.2 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 Metricool\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): PromiseInterface
14 {
15 if ($value instanceof 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 Promise($wfn, $cfn);
23 $value->then([$promise, 'resolve'], [$promise, 'reject']);
24 return $promise;
25 }
26 return new 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): PromiseInterface
35 {
36 if ($reason instanceof PromiseInterface) {
37 return $reason;
38 }
39 return new 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 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 \Metricool\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