1 | <?php |
||
34 | class Ipv6Range implements IpRange |
||
35 | { |
||
36 | |||
37 | /** The size of the IPv6 range mask. */ |
||
38 | private $mask; |
||
39 | |||
40 | /** The binary substring of the range minus the mask. */ |
||
41 | private $rangeSubstring; |
||
42 | |||
43 | /** |
||
44 | * Constructor for the class. |
||
45 | * @param string $range The IPv6 range as a string. Supported range styles: |
||
46 | * - CIDR notation (2400:cb00::/32) |
||
47 | * - a specific IP address (::1) |
||
48 | */ |
||
49 | 8 | public function __construct($range) |
|
53 | |||
54 | /** |
||
55 | * Returns whether or not a given IP address falls within this range. |
||
56 | * @param string $ipAddress The given IP address. |
||
57 | * @return boolean Returns true if the IP address falls within the range |
||
58 | * and false otherwise. |
||
59 | */ |
||
60 | 3 | public function containsIp($ipAddress) |
|
76 | |||
77 | /** |
||
78 | * Extracts the mask and binary string substring of the range to compare |
||
79 | * against incoming IP addresses. |
||
80 | * @param string $range The IPv6 range as a string. |
||
81 | */ |
||
82 | 8 | private function extractNetworkAndMaskFromRange($range) |
|
100 | |||
101 | /** |
||
102 | * Converts an IPv6 address to a binary string. |
||
103 | * @param string $address The IPv6 address in standard notation. |
||
104 | * @return string Returns the address as a string of bits. |
||
105 | */ |
||
106 | 8 | private function convertToBinaryString($address) |
|
113 | /** |
||
114 | * Converts a hexadecimal character to a 4-digit binary string. |
||
115 | * @param string $hex The hexadecimal character. |
||
116 | * @return string Returns a 4-digit binary string. |
||
117 | */ |
||
118 | 8 | private static function hexToBinary($hex) |
|
122 | } |
||
123 |