You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/vendor/php-http/httplug/src/Promise/HttpRejectedPromise.php

58 lines
1.1 KiB

<?php
namespace Http\Client\Promise;
use Http\Client\Exception;
use Http\Promise\Promise;
final class HttpRejectedPromise implements Promise
{
/**
* @var Exception
*/
private $exception;
public function __construct(Exception $exception)
{
$this->exception = $exception;
}
/**
* {@inheritdoc}
*/
public function then(callable $onFulfilled = null, callable $onRejected = null)
{
if (null === $onRejected) {
return $this;
}
try {
$result = $onRejected($this->exception);
if ($result instanceof Promise) {
return $result;
}
return new HttpFulfilledPromise($result);
} catch (Exception $e) {
return new self($e);
}
}
/**
* {@inheritdoc}
*/
public function getState()
{
return Promise::REJECTED;
}
/**
* {@inheritdoc}
*/
public function wait($unwrap = true)
{
if ($unwrap) {
throw $this->exception;
}
}
}