1 | <?php |
||
8 | class IBAN |
||
9 | { |
||
10 | const MAX_LENGTH = 34; |
||
11 | const PATTERN = '/^[A-Z]{2,2}[0-9]{2,2}[A-Z0-9]{1,30}$/'; |
||
12 | |||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $iban; |
||
17 | |||
18 | /** |
||
19 | * Constructor |
||
20 | * |
||
21 | * @param string $iban |
||
22 | * |
||
23 | * @throws \InvalidArgumentException When the IBAN does contain invalid characters or the checksum calculation fails. |
||
24 | */ |
||
25 | 8 | public function __construct($iban) |
|
37 | |||
38 | /** |
||
39 | * Format the IBAN either in a human-readable manner |
||
40 | * |
||
41 | * @return string The formatted IBAN |
||
42 | */ |
||
43 | 1 | public function format() |
|
49 | |||
50 | /** |
||
51 | * Normalize the IBAN |
||
52 | * |
||
53 | * @return string The normalized IBAN |
||
54 | */ |
||
55 | 3 | public function normalize() |
|
59 | |||
60 | /** |
||
61 | * Gets the country |
||
62 | * |
||
63 | * @return string A ISO 3166-1 alpha-2 country code |
||
64 | */ |
||
65 | 6 | public function getCountry() |
|
69 | |||
70 | /** |
||
71 | * Checks whether the checksum of an IBAN is correct |
||
72 | * |
||
73 | * @param string $iban |
||
74 | * |
||
75 | * @return bool true if checksum is correct, false otherwise |
||
76 | */ |
||
77 | 3 | protected static function check($iban) |
|
102 | |||
103 | /** |
||
104 | * Returns a string representation. |
||
105 | * |
||
106 | * @return string The string representation. |
||
107 | */ |
||
108 | 3 | public function __toString() |
|
112 | } |
||
113 |