Mercurial > hg > isophonics-drupal-site
comparison vendor/guzzlehttp/promises/src/RejectionException.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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 } |