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.
 
 
 
 
 
 

48 regels
1.2 KiB

  1. <?php
  2. namespace GuzzleHttp\Promise;
  3. /**
  4. * A special exception that is thrown when waiting on a rejected promise.
  5. *
  6. * The reason value is available via the getReason() method.
  7. */
  8. class RejectionException extends \RuntimeException
  9. {
  10. /** @var mixed Rejection reason. */
  11. private $reason;
  12. /**
  13. * @param mixed $reason Rejection reason.
  14. * @param string $description Optional description
  15. */
  16. public function __construct($reason, $description = null)
  17. {
  18. $this->reason = $reason;
  19. $message = 'The promise was rejected';
  20. if ($description) {
  21. $message .= ' with reason: ' . $description;
  22. } elseif (is_string($reason)
  23. || (is_object($reason) && method_exists($reason, '__toString'))
  24. ) {
  25. $message .= ' with reason: ' . $this->reason;
  26. } elseif ($reason instanceof \JsonSerializable) {
  27. $message .= ' with reason: '
  28. . json_encode($this->reason, JSON_PRETTY_PRINT);
  29. }
  30. parent::__construct($message);
  31. }
  32. /**
  33. * Returns the rejection reason.
  34. *
  35. * @return mixed
  36. */
  37. public function getReason()
  38. {
  39. return $this->reason;
  40. }
  41. }