| 1 |
<?php |
| 2 |
|
| 3 |
namespace Http\Promise; |
| 4 |
|
| 5 |
/** |
| 6 |
* A rejected promise. |
| 7 |
* |
| 8 |
* @author Joel Wurtz <[email protected]> |
| 9 |
*/ |
| 10 |
final class RejectedPromise implements Promise |
| 11 |
{ |
| 12 |
/** |
| 13 |
* @var \Throwable |
| 14 |
*/ |
| 15 |
private $exception; |
| 16 |
|
| 17 |
public function __construct(\Throwable $exception) |
| 18 |
{ |
| 19 |
$this->exception = $exception; |
| 20 |
} |
| 21 |
|
| 22 |
public function then(?callable $onFulfilled = null, ?callable $onRejected = null) |
| 23 |
{ |
| 24 |
if (null === $onRejected) { |
| 25 |
return $this; |
| 26 |
} |
| 27 |
|
| 28 |
try { |
| 29 |
return new FulfilledPromise($onRejected($this->exception)); |
| 30 |
} catch (\Exception $e) { |
| 31 |
return new self($e); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
public function getState() |
| 36 |
{ |
| 37 |
return Promise::REJECTED; |
| 38 |
} |
| 39 |
|
| 40 |
public function wait($unwrap = true) |
| 41 |
{ |
| 42 |
if ($unwrap) { |
| 43 |
throw $this->exception; |
| 44 |
} |
| 45 |
|
| 46 |
return null; |
| 47 |
} |
| 48 |
} |
| 49 |
|