PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.8
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.8
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 / FulfilledPromise.php

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

70 lines 2.0 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 /**
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 \YoastSEO_Vendor\GuzzleHttp\Promise\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 = \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::queue();
28 $p = new \YoastSEO_Vendor\GuzzleHttp\Promise\Promise([$queue, 'run']);
29 $value = $this->value;
30 $queue->add(static function () use($p, $value, $onFulfilled) {
31 if (\YoastSEO_Vendor\GuzzleHttp\Promise\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