class FulfilledPromise
Same name in this branch
- 11.1.x vendor/react/promise/src/Internal/FulfilledPromise.php \React\Promise\Internal\FulfilledPromise
- 11.1.x vendor/php-http/promise/src/FulfilledPromise.php \Http\Promise\FulfilledPromise
A promise that has been fulfilled.
Thenning off of this promise will invoke the onFulfilled callback immediately and ignore other callbacks.
@final
Hierarchy
- class \GuzzleHttp\Promise\FulfilledPromise implements \GuzzleHttp\Promise\PromiseInterface
Expanded class hierarchy of FulfilledPromise
2 files declare their use of FulfilledPromise
- CurlFactory.php in vendor/
guzzlehttp/ guzzle/ src/ Handler/ CurlFactory.php - StreamHandler.php in vendor/
guzzlehttp/ guzzle/ src/ Handler/ StreamHandler.php
File
-
vendor/
guzzlehttp/ promises/ src/ FulfilledPromise.php, line 15
Namespace
GuzzleHttp\PromiseView source
class FulfilledPromise implements PromiseInterface {
private $value;
/**
* @param mixed $value
*/
public function __construct($value) {
if (is_object($value) && method_exists($value, 'then')) {
throw new \InvalidArgumentException('You cannot create a FulfilledPromise with a promise.');
}
$this->value = $value;
}
public function then(?callable $onFulfilled = null, ?callable $onRejected = null) : PromiseInterface {
// Return itself if there is no onFulfilled function.
if (!$onFulfilled) {
return $this;
}
$queue = Utils::queue();
$p = new Promise([
$queue,
'run',
]);
$value = $this->value;
$queue->add(static function () use ($p, $value, $onFulfilled) : void {
if (Is::pending($p)) {
try {
$p->resolve($onFulfilled($value));
} catch (\Throwable $e) {
$p->reject($e);
}
}
});
return $p;
}
public function otherwise(callable $onRejected) : PromiseInterface {
return $this->then(null, $onRejected);
}
public function wait(bool $unwrap = true) {
return $unwrap ? $this->value : null;
}
public function getState() : string {
return self::FULFILLED;
}
public function resolve($value) : void {
if ($value !== $this->value) {
throw new \LogicException('Cannot resolve a fulfilled promise');
}
}
public function reject($reason) : void {
throw new \LogicException('Cannot reject a fulfilled promise');
}
public function cancel() : void {
// pass
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
FulfilledPromise::$value | private | property | ||
FulfilledPromise::cancel | public | function | Cancels the promise if possible. | Overrides PromiseInterface::cancel |
FulfilledPromise::getState | public | function | Get the state of the promise ("pending", "rejected", or "fulfilled"). | Overrides PromiseInterface::getState |
FulfilledPromise::otherwise | public | function | Appends a rejection handler callback to the promise, and returns a new promise resolving to the return value of the callback if it is called, or to its original fulfillment value if the promise is instead fulfilled. |
Overrides PromiseInterface::otherwise |
FulfilledPromise::reject | public | function | Reject the promise with the given reason. | Overrides PromiseInterface::reject |
FulfilledPromise::resolve | public | function | Resolve the promise with the given value. | Overrides PromiseInterface::resolve |
FulfilledPromise::then | public | function | Appends fulfillment and rejection handlers to the promise, and returns a new promise resolving to the return value of the called handler. |
Overrides PromiseInterface::then |
FulfilledPromise::wait | public | function | Waits until the promise completes if possible. | Overrides PromiseInterface::wait |
FulfilledPromise::__construct | public | function | ||
PromiseInterface::FULFILLED | public | constant | ||
PromiseInterface::PENDING | public | constant | ||
PromiseInterface::REJECTED | public | constant |