update all libraries
This commit is contained in:
63
vendor/mlocati/ip-lib/src/Range/Subnet.php
vendored
63
vendor/mlocati/ip-lib/src/Range/Subnet.php
vendored
@@ -4,9 +4,9 @@ namespace IPLib\Range;
|
||||
|
||||
use IPLib\Address\AddressInterface;
|
||||
use IPLib\Address\IPv4;
|
||||
use IPLib\Address\IPv6;
|
||||
use IPLib\Address\Type as AddressType;
|
||||
use IPLib\Factory;
|
||||
use IPLib\ParseStringFlag;
|
||||
|
||||
/**
|
||||
* Represents an address range in subnet format (eg CIDR).
|
||||
@@ -41,6 +41,8 @@ class Subnet extends AbstractRange
|
||||
* The type of the range of this IP range.
|
||||
*
|
||||
* @var int|null
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
protected $rangeType;
|
||||
|
||||
@@ -77,15 +79,36 @@ class Subnet extends AbstractRange
|
||||
return $this->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 1.17.0: use the parseString() method instead.
|
||||
* For upgrading:
|
||||
* - if $supportNonDecimalIPv4 is true, use the ParseStringFlag::IPV4_MAYBE_NON_DECIMAL flag
|
||||
*
|
||||
* @param string|mixed $range
|
||||
* @param bool $supportNonDecimalIPv4
|
||||
*
|
||||
* @return static|null
|
||||
*
|
||||
* @see \IPLib\Range\Subnet::parseString()
|
||||
* @since 1.10.0 added the $supportNonDecimalIPv4 argument
|
||||
*/
|
||||
public static function fromString($range, $supportNonDecimalIPv4 = false)
|
||||
{
|
||||
return static::parseString($range, ParseStringFlag::MAY_INCLUDE_PORT | ParseStringFlag::MAY_INCLUDE_ZONEID | ($supportNonDecimalIPv4 ? ParseStringFlag::IPV4_MAYBE_NON_DECIMAL : 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Try get the range instance starting from its string representation.
|
||||
*
|
||||
* @param string|mixed $range
|
||||
* @param bool $supportNonDecimalIPv4 set to true to support parsing non decimal (that is, octal and hexadecimal) IPv4 addresses
|
||||
* @param int $flags A combination or zero or more flags
|
||||
*
|
||||
* @return static|null
|
||||
*
|
||||
* @see \IPLib\ParseStringFlag
|
||||
* @since 1.17.0
|
||||
*/
|
||||
public static function fromString($range, $supportNonDecimalIPv4 = false)
|
||||
public static function parseString($range, $flags = 0)
|
||||
{
|
||||
if (!is_string($range)) {
|
||||
return null;
|
||||
@@ -94,7 +117,14 @@ class Subnet extends AbstractRange
|
||||
if (count($parts) !== 2) {
|
||||
return null;
|
||||
}
|
||||
$address = Factory::addressFromString($parts[0], true, true, $supportNonDecimalIPv4);
|
||||
$flags = (int) $flags;
|
||||
if (strpos($parts[0], ':') === false && $flags & ParseStringFlag::IPV4SUBNET_MAYBE_COMPACT) {
|
||||
$missingDots = 3 - substr_count($parts[0], '.');
|
||||
if ($missingDots > 0) {
|
||||
$parts[0] .= str_repeat('.0', $missingDots);
|
||||
}
|
||||
}
|
||||
$address = Factory::parseAddressString($parts[0], $flags);
|
||||
if ($address === null) {
|
||||
return null;
|
||||
}
|
||||
@@ -197,9 +227,10 @@ class Subnet extends AbstractRange
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pattern (asterisk) representation (if applicable) of this range.
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return \IPLib\Range\Pattern|null return NULL if this range can't be represented by a pattern notation
|
||||
* @see \IPLib\Range\RangeInterface::asPattern()
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public function asPattern()
|
||||
{
|
||||
@@ -217,11 +248,13 @@ class Subnet extends AbstractRange
|
||||
* Get the 6to4 address IPv6 address range.
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static function get6to4()
|
||||
{
|
||||
if (self::$sixToFour === null) {
|
||||
self::$sixToFour = self::fromString('2002::/16');
|
||||
self::$sixToFour = self::parseString('2002::/16');
|
||||
}
|
||||
|
||||
return self::$sixToFour;
|
||||
@@ -231,6 +264,8 @@ class Subnet extends AbstractRange
|
||||
* Get subnet prefix.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public function getNetworkPrefix()
|
||||
{
|
||||
@@ -302,4 +337,18 @@ class Subnet extends AbstractRange
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \IPLib\Range\RangeInterface::getSize()
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
$fromAddress = $this->fromAddress;
|
||||
$maxPrefix = $fromAddress::getNumberOfBits();
|
||||
$prefix = $this->getNetworkPrefix();
|
||||
|
||||
return pow(2, ($maxPrefix - $prefix));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user