PluginProbe
Media Cloud Sync / 1.2.2
Media Cloud Sync v1.2.2
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / GuzzleHttp / Promise / FulfilledPromise.php

FulfilledPromise.php in Media Cloud Sync 1.2.2, at includes/sdk/s3/GuzzleHttp/Promise/FulfilledPromise.php

70 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\GuzzleHttp\Promise;
4
5 /**
6 * A promise that has been fulfilled.
7 *
8 * Thenning off of this promise will invoke the onFulfilled callback
9 * immediately and ignore other callbacks.
10 */
11 class FulfilledPromise implements PromiseInterface
12 {
13 private $value;
14 public function __construct($value)
15 {
16 if (\is_object($value) && \method_exists($value, 'then')) {
17 throw new \InvalidArgumentException('You cannot create a FulfilledPromise with a promise.');
18 }
19 $this->value = $value;
20 }
21 public function then(callable $onFulfilled = null, callable $onRejected = null)
22 {
23 // Return itself if there is no onFulfilled function.
24 if (!$onFulfilled) {
25 return $this;
26 }
27 $queue = Utils::queue();
28 $p = new Promise([$queue, 'run']);
29 $value = $this->value;
30 $queue->add(static function () use($p, $value, $onFulfilled) {
31 if (Is::pending($p)) {
32 try {
33 $p->resolve($onFulfilled($value));
34 } catch (\Throwable $e) {
35 $p->reject($e);
36 } catch (\Exception $e) {
37 $p->reject($e);
38 }
39 }
40 });
41 return $p;
42 }
43 public function otherwise(callable $onRejected)
44 {
45 return $this->then(null, $onRejected);
46 }
47 public function wait($unwrap = \true, $defaultDelivery = null)
48 {
49 return $unwrap ? $this->value : null;
50 }
51 public function getState()
52 {
53 return self::FULFILLED;
54 }
55 public function resolve($value)
56 {
57 if ($value !== $this->value) {
58 throw new \LogicException("Cannot resolve a fulfilled promise");
59 }
60 }
61 public function reject($reason)
62 {
63 throw new \LogicException("Cannot reject a fulfilled promise");
64 }
65 public function cancel()
66 {
67 // pass
68 }
69 }
70