You are here

class RejectedPromise in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/guzzlehttp/promises/src/RejectedPromise.php \GuzzleHttp\Promise\RejectedPromise

A promise that has been rejected.

Thenning off of this promise will invoke the onRejected callback immediately and ignore other callbacks.

Hierarchy

Expanded class hierarchy of RejectedPromise

9 files declare their use of RejectedPromise
CurlFactory.php in vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php
EachPromiseTest.php in vendor/guzzlehttp/promises/tests/EachPromiseTest.php
functionsTest.php in vendor/guzzlehttp/promises/tests/functionsTest.php
Middleware.php in vendor/guzzlehttp/guzzle/src/Middleware.php
MockHandler.php in vendor/guzzlehttp/guzzle/src/Handler/MockHandler.php

... See full list

File

vendor/guzzlehttp/promises/src/RejectedPromise.php, line 10

Namespace

GuzzleHttp\Promise
View source
class RejectedPromise implements PromiseInterface {
  private $reason;
  public function __construct($reason) {
    if (method_exists($reason, 'then')) {
      throw new \InvalidArgumentException('You cannot create a RejectedPromise with a promise.');
    }
    $this->reason = $reason;
  }
  public function then(callable $onFulfilled = null, callable $onRejected = null) {

    // If there's no onRejected callback then just return self.
    if (!$onRejected) {
      return $this;
    }
    $queue = queue();
    $reason = $this->reason;
    $p = new Promise([
      $queue,
      'run',
    ]);
    $queue
      ->add(static function () use ($p, $reason, $onRejected) {
      if ($p
        ->getState() === self::PENDING) {
        try {

          // Return a resolved promise if onRejected does not throw.
          $p
            ->resolve($onRejected($reason));
        } catch (\Exception $e) {

          // onRejected threw, so return a rejected promise.
          $p
            ->reject($e);
        }
      }
    });
    return $p;
  }
  public function otherwise(callable $onRejected) {
    return $this
      ->then(null, $onRejected);
  }
  public function wait($unwrap = true, $defaultDelivery = null) {
    if ($unwrap) {
      throw exception_for($this->reason);
    }
  }
  public function getState() {
    return self::REJECTED;
  }
  public function resolve($value) {
    throw new \LogicException("Cannot resolve a rejected promise");
  }
  public function reject($reason) {
    if ($reason !== $this->reason) {
      throw new \LogicException("Cannot reject a rejected promise");
    }
  }
  public function cancel() {

    // pass
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PromiseInterface::FULFILLED constant
PromiseInterface::PENDING constant
PromiseInterface::REJECTED constant
RejectedPromise::$reason private property
RejectedPromise::cancel public function Cancels the promise if possible. Overrides PromiseInterface::cancel
RejectedPromise::getState public function Get the state of the promise ("pending", "rejected", or "fulfilled"). Overrides PromiseInterface::getState
RejectedPromise::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
RejectedPromise::reject public function Reject the promise with the given reason. Overrides PromiseInterface::reject
RejectedPromise::resolve public function Resolve the promise with the given value. Overrides PromiseInterface::resolve
RejectedPromise::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
RejectedPromise::wait public function Waits until the promise completes if possible. Overrides PromiseInterface::wait
RejectedPromise::__construct public function