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