|
Last change
on this file since a2330fc was 01a620f, checked in by Joachim Langenbach <joachim.langenbach@…>, 11 years ago |
|
Removed submodules for php externals and use composer to provide them and versioned them afterwards
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Rev | Line | |
|---|
| [01a620f] | 1 | <?php
|
|---|
| 2 | namespace GuzzleHttp\Promise;
|
|---|
| 3 |
|
|---|
| 4 | /**
|
|---|
| 5 | * A special exception that is thrown when waiting on a rejected promise.
|
|---|
| 6 | *
|
|---|
| 7 | * The reason value is available via the getReason() method.
|
|---|
| 8 | */
|
|---|
| 9 | class RejectionException extends \RuntimeException
|
|---|
| 10 | {
|
|---|
| 11 | /** @var mixed Rejection reason. */
|
|---|
| 12 | private $reason;
|
|---|
| 13 |
|
|---|
| 14 | /**
|
|---|
| 15 | * @param mixed $reason Rejection reason.
|
|---|
| 16 | * @param string $description Optional description
|
|---|
| 17 | */
|
|---|
| 18 | public function __construct($reason, $description = null)
|
|---|
| 19 | {
|
|---|
| 20 | $this->reason = $reason;
|
|---|
| 21 |
|
|---|
| 22 | $message = 'The promise was rejected';
|
|---|
| 23 |
|
|---|
| 24 | if ($description) {
|
|---|
| 25 | $message .= ' with reason: ' . $description;
|
|---|
| 26 | } elseif (is_string($reason)
|
|---|
| 27 | || (is_object($reason) && method_exists($reason, '__toString'))
|
|---|
| 28 | ) {
|
|---|
| 29 | $message .= ' with reason: ' . $this->reason;
|
|---|
| 30 | } elseif ($reason instanceof \JsonSerializable) {
|
|---|
| 31 | $message .= ' with reason: '
|
|---|
| 32 | . json_encode($this->reason, JSON_PRETTY_PRINT);
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | parent::__construct($message);
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | /**
|
|---|
| 39 | * Returns the rejection reason.
|
|---|
| 40 | *
|
|---|
| 41 | * @return mixed
|
|---|
| 42 | */
|
|---|
| 43 | public function getReason()
|
|---|
| 44 | {
|
|---|
| 45 | return $this->reason;
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.