You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* [feat] add method split to range ips, to convert range smaller range
* [refactor] change split method to array
* [style]
* [refactor] delete interface split
* [test] add test
* [style]
* [test] php 5.3, 5.4, 5.5 compatibility
* Describe the type of the result of the split method
* Be sure that we receive an int as the argument of the split method
* Always run all tests
* Fix and simplify tests
* Use Coveralls only for the mlocati's repo
* Simplify "if" statements
* Document that split() can throw a \RuntimeException
* Optimization + accept a network prefix that's the same as the range's one
* Use OutOfBoundsException if $networkPrefix is invalid
* Check maximum range sizes for 32-bit systems
* Fix running Coveralls
* [feat] handle pattern range and update DocBlock
* [fix] move split method to single class
* [fix] fix class pattern
* [chore] update return type
* [test] add single test and pattern test
* [style] add readme
* [style]
* Add getNetworkPrefix() to RangeInterface
This implies checking $networkPrefix for Single::split() too, without efforts
* Add $forceSubnet parameter, test overflow for 64-bit systems too
* Fix coding style
* Improve documentation about the split() method
* Add @SInCE to split()
---------
Co-authored-by: Michele Locati <[email protected]>
thrownewOutOfBoundsException("The value of the \$networkPrefix parameter can't be smaller than the network prefix of the range ({$myNetworkPrefix})");
144
+
}
145
+
$startIp = $this->getStartAddress();
146
+
$maxPrefix = $startIp::getNumberOfBits();
147
+
if ($networkPrefix > $maxPrefix) {
148
+
thrownewOutOfBoundsException("The value of the \$networkPrefix parameter can't be larger than the maximum network prefix of the range ({$maxPrefix})");
thrownewOverflowException("The value of \$networkPrefix leads to too large ranges for the current machine bitness (you can use a value of at least {$minPrefixByBitness})");
Copy file name to clipboardExpand all lines: src/Range/RangeInterface.php
+27Lines changed: 27 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -157,4 +157,31 @@ public function getReverseDNSLookupName();
157
157
* @since 1.16.0
158
158
*/
159
159
publicfunctiongetSize();
160
+
161
+
/**
162
+
* Get the "network prefix", that is how many bits of the address are dedicated to the network portion.
163
+
*
164
+
* @return int
165
+
*
166
+
* @since 1.19.0
167
+
*
168
+
* @example for 10.0.0.0/24 it's 24
169
+
* @example for 10.0.0.* it's 24
170
+
*/
171
+
publicfunctiongetNetworkPrefix();
172
+
173
+
/**
174
+
* Split the range into smaller ranges.
175
+
*
176
+
* @param int $networkPrefix
177
+
* @param bool $forceSubnet set to true to always have ranges in "subnet format" (ie 1.2.3.4/5), to false to try to keep the original format if possible (that is, pattern to pattern, single to single)
178
+
*
179
+
* @throws \OutOfBoundsException if $networkPrefix is not valid
180
+
* @throws \OverflowException if you are running a 32-bit system and the ranges are too wide
0 commit comments