1 | <?php |
||
21 | class IpRange implements JsonSerializable |
||
22 | { |
||
23 | /** |
||
24 | * beginning IP address of the range |
||
25 | * |
||
26 | * @ORM\Embedded(class="DDD\Embeddable\IpAddress") |
||
27 | * |
||
28 | * @var IpAddress |
||
29 | */ |
||
30 | protected $startIp; |
||
31 | |||
32 | /** |
||
33 | * high IP address of the range |
||
34 | * |
||
35 | * @ORM\Embedded(class="DDD\Embeddable\IpAddress") |
||
36 | * |
||
37 | * @var IpAddress |
||
38 | */ |
||
39 | protected $endIp; |
||
40 | |||
41 | /** |
||
42 | * Constructor. |
||
43 | * |
||
44 | * @param IpAddress $startIp |
||
45 | * @param IpAddress $endIp |
||
46 | */ |
||
47 | 3 | public function __construct(IpAddress $startIp = null, IpAddress $endIp = null) |
|
52 | |||
53 | /** |
||
54 | * Returns the low IP addresses of this range. |
||
55 | * |
||
56 | * @return IpAddress |
||
57 | */ |
||
58 | 2 | public function getStartIp() |
|
62 | |||
63 | /** |
||
64 | * Returns the high IP addresses of this range. |
||
65 | * |
||
66 | * @return IpAddress |
||
67 | */ |
||
68 | 2 | public function getEndIp() |
|
72 | |||
73 | /** |
||
74 | * Create a new range from CIDR notation. |
||
75 | * CIDR notation is a compact representation of an IP address(es) |
||
76 | * and its associated routing prefix. |
||
77 | * |
||
78 | * @static |
||
79 | * |
||
80 | * @param string $cidr |
||
81 | * |
||
82 | * @return self |
||
83 | */ |
||
84 | 2 | public static function createFromCidrNotation($cidr) |
|
92 | |||
93 | /** |
||
94 | * String representation of a range. |
||
95 | * |
||
96 | * Example output: "192.168.0.10 - 192.168.0.255" |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | 1 | public function __toString() |
|
104 | |||
105 | /** |
||
106 | * Array representation of the ip range |
||
107 | * |
||
108 | * @return array |
||
109 | */ |
||
110 | 3 | public function toArray() |
|
121 | |||
122 | /** |
||
123 | * Returns boolean TRUE if the range is empty, false otherwise. |
||
124 | * |
||
125 | * @return boolean |
||
126 | */ |
||
127 | 3 | public function isEmpty() |
|
131 | |||
132 | /** |
||
133 | * Implement json serializable interface. |
||
134 | * |
||
135 | * @return array |
||
136 | */ |
||
137 | 2 | public function jsonSerialize() |
|
141 | } |
||
142 |