Mercurial > hg > isophonics-drupal-site
annotate vendor/guzzlehttp/promises/src/RejectionException.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 4c8ae668cc8c |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 namespace GuzzleHttp\Promise; |
Chris@0 | 3 |
Chris@0 | 4 /** |
Chris@0 | 5 * A special exception that is thrown when waiting on a rejected promise. |
Chris@0 | 6 * |
Chris@0 | 7 * The reason value is available via the getReason() method. |
Chris@0 | 8 */ |
Chris@0 | 9 class RejectionException extends \RuntimeException |
Chris@0 | 10 { |
Chris@0 | 11 /** @var mixed Rejection reason. */ |
Chris@0 | 12 private $reason; |
Chris@0 | 13 |
Chris@0 | 14 /** |
Chris@0 | 15 * @param mixed $reason Rejection reason. |
Chris@0 | 16 * @param string $description Optional description |
Chris@0 | 17 */ |
Chris@0 | 18 public function __construct($reason, $description = null) |
Chris@0 | 19 { |
Chris@0 | 20 $this->reason = $reason; |
Chris@0 | 21 |
Chris@0 | 22 $message = 'The promise was rejected'; |
Chris@0 | 23 |
Chris@0 | 24 if ($description) { |
Chris@0 | 25 $message .= ' with reason: ' . $description; |
Chris@0 | 26 } elseif (is_string($reason) |
Chris@0 | 27 || (is_object($reason) && method_exists($reason, '__toString')) |
Chris@0 | 28 ) { |
Chris@0 | 29 $message .= ' with reason: ' . $this->reason; |
Chris@0 | 30 } elseif ($reason instanceof \JsonSerializable) { |
Chris@0 | 31 $message .= ' with reason: ' |
Chris@0 | 32 . json_encode($this->reason, JSON_PRETTY_PRINT); |
Chris@0 | 33 } |
Chris@0 | 34 |
Chris@0 | 35 parent::__construct($message); |
Chris@0 | 36 } |
Chris@0 | 37 |
Chris@0 | 38 /** |
Chris@0 | 39 * Returns the rejection reason. |
Chris@0 | 40 * |
Chris@0 | 41 * @return mixed |
Chris@0 | 42 */ |
Chris@0 | 43 public function getReason() |
Chris@0 | 44 { |
Chris@0 | 45 return $this->reason; |
Chris@0 | 46 } |
Chris@0 | 47 } |