| @@ 30-48 (lines=19) @@ | ||
| 27 | /** @var int */ |
|
| 28 | private $prefix; |
|
| 29 | ||
| 30 | public function __construct($cidrIp) |
|
| 31 | { |
|
| 32 | // must be of form IP/PREFIX |
|
| 33 | if (1 !== substr_count($cidrIp, '/')) { |
|
| 34 | throw new InvalidArgumentException('not in CIDR format'); |
|
| 35 | } |
|
| 36 | list($ip, $prefix) = explode('/', $cidrIp); |
|
| 37 | ||
| 38 | // check IP |
|
| 39 | self::validateIP($ip); |
|
| 40 | $this->ip = $ip; |
|
| 41 | ||
| 42 | // check prefix |
|
| 43 | if (!is_numeric($prefix) || 0 > $prefix || 32 < $prefix) { |
|
| 44 | throw new InvalidArgumentException('invalid prefix, must be >0 and <32'); |
|
| 45 | } |
|
| 46 | ||
| 47 | $this->prefix = intval($prefix); |
|
| 48 | } |
|
| 49 | ||
| 50 | public function getRange() |
|
| 51 | { |
|
| @@ 30-48 (lines=19) @@ | ||
| 27 | /** @var int */ |
|
| 28 | private $prefix; |
|
| 29 | ||
| 30 | public function __construct($prefixIp) |
|
| 31 | { |
|
| 32 | // must be of form IP/PREFIX |
|
| 33 | if (1 !== substr_count($prefixIp, '/')) { |
|
| 34 | throw new InvalidArgumentException('not a prefix'); |
|
| 35 | } |
|
| 36 | list($ip, $prefix) = explode('/', $prefixIp); |
|
| 37 | ||
| 38 | // check IP |
|
| 39 | self::validateIP($ip); |
|
| 40 | $this->ip = inet_ntop(inet_pton($ip)); |
|
| 41 | ||
| 42 | // check prefix |
|
| 43 | if (!is_numeric($prefix) || 0 > $prefix || 64 < $prefix) { |
|
| 44 | throw new InvalidArgumentException('invalid prefix, must be <= /64'); |
|
| 45 | } |
|
| 46 | ||
| 47 | $this->prefix = intval($prefix); |
|
| 48 | } |
|
| 49 | ||
| 50 | public function getRange() |
|
| 51 | { |
|