NumberParseException.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace libphonenumber;
  3. /**
  4. * Generic exception class for errors encountered when parsing phone numbers.
  5. * @author Lara Rennie
  6. */
  7. class NumberParseException extends \Exception
  8. {
  9. /**
  10. * The country code supplied did not belong to a supported country or non-geographical entity.
  11. */
  12. const INVALID_COUNTRY_CODE = 0;
  13. /**
  14. * This indicates the string passed is not a valid number. Either the string had less than 3
  15. * digits in it or had an invalid phone-context parameter. More specifically, the number failed
  16. * to match the regular expression VALID_PHONE_NUMBER, RFC3966_GLOBAL_NUMBER_DIGITS, or
  17. * RFC3966_DOMAINNAME in PhoneNumberUtil
  18. */
  19. const NOT_A_NUMBER = 1;
  20. /**
  21. * This indicates the string started with an international dialing prefix, but after this was
  22. * stripped from the number, had less digits than any valid phone number (including country
  23. * code) could have.
  24. */
  25. const TOO_SHORT_AFTER_IDD = 2;
  26. /**
  27. * This indicates the string, after any country code has been stripped, had less digits than any
  28. * valid phone number could have.
  29. */
  30. const TOO_SHORT_NSN = 3;
  31. /**
  32. * This indicates the string had more digits than any valid phone number could have.
  33. */
  34. const TOO_LONG = 4;
  35. protected $errorType;
  36. public function __construct($errorType, $message, $previous = null)
  37. {
  38. parent::__construct($message, $errorType, $previous);
  39. $this->message = $message;
  40. $this->errorType = $errorType;
  41. }
  42. /**
  43. * Returns the error type of the exception that has been thrown.
  44. */
  45. public function getErrorType()
  46. {
  47. return $this->errorType;
  48. }
  49. public function __toString()
  50. {
  51. return 'Error type: ' . $this->errorType . '. ' . $this->message;
  52. }
  53. }