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

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

76 lines 2.4 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 rejected.
7 *
8 * Thenning off of this promise will invoke the onRejected callback
9 * immediately and ignore other callbacks.
10 */
11 class RejectedPromise implements \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
12 {
13 private $reason;
14 public function __construct($reason)
15 {
16 if (\is_object($reason) && \method_exists($reason, 'then')) {
17 throw new \InvalidArgumentException('You cannot create a RejectedPromise with a promise.');
18 }
19 $this->reason = $reason;
20 }
21 public function then(callable $onFulfilled = null, callable $onRejected = null)
22 {
23 // If there's no onRejected callback then just return self.
24 if (!$onRejected) {
25 return $this;
26 }
27 $queue = \YoastSEO_Vendor\GuzzleHttp\Promise\Utils::queue();
28 $reason = $this->reason;
29 $p = new \YoastSEO_Vendor\GuzzleHttp\Promise\Promise([$queue, 'run']);
30 $queue->add(static function () use($p, $reason, $onRejected) {
31 if (\YoastSEO_Vendor\GuzzleHttp\Promise\Is::pending($p)) {
32 try {
33 // Return a resolved promise if onRejected does not throw.
34 $p->resolve($onRejected($reason));
35 } catch (\Throwable $e) {
36 // onRejected threw, so return a rejected promise.
37 $p->reject($e);
38 } catch (\Exception $e) {
39 // onRejected threw, so return a rejected promise.
40 $p->reject($e);
41 }
42 }
43 });
44 return $p;
45 }
46 public function otherwise(callable $onRejected)
47 {
48 return $this->then(null, $onRejected);
49 }
50 public function wait($unwrap = \true, $defaultDelivery = null)
51 {
52 if ($unwrap) {
53 throw \YoastSEO_Vendor\GuzzleHttp\Promise\Create::exceptionFor($this->reason);
54 }
55 return null;
56 }
57 public function getState()
58 {
59 return self::REJECTED;
60 }
61 public function resolve($value)
62 {
63 throw new \LogicException("Cannot resolve a rejected promise");
64 }
65 public function reject($reason)
66 {
67 if ($reason !== $this->reason) {
68 throw new \LogicException("Cannot reject a rejected promise");
69 }
70 }
71 public function cancel()
72 {
73 // pass
74 }
75 }
76