Ranges ###### .. highlight:: php Classes ======= There are 4 classes representing ranges: ``Arokettu\IP\IPv4Range`` IPv4 range ``Arokettu\IP\IPv6Range`` IPv6 range ``Arokettu\IP\IPRange`` Common factory methods with version autodetection ``Arokettu\IP\AnyIPRange`` An interface meaning both ``IPv4Range`` and ``IPv6Range`` Factories ========= ``fromBytes()`` --------------- * ``Arokettu\IP\IPv4Range::fromBytes($bytes, $prefix, $strict = false)`` * ``Arokettu\IP\IPv6Range::fromBytes($bytes, $prefix, $strict = false)`` * ``Arokettu\IP\IPRange::fromBytes($bytes, $prefix, $strict = false)`` Creates an object from a byte representation of the base address (such as created by the ``inet_pton()`` function) and a prefix value. Non-strict mode allows non-normalized base address and negative prefixes (for IPv4 -1 equals to 32 and -32 equals to 1):: contains($ip1); // true $range1->contains($ip2); // false $range1->contains($ip2, strict: true); // TypeError $range1->contains($range2); // true Comparison ---------- .. note:: See :ref:`compare-helper` Also exists in 3 versions: * ``strictCompare($address)`` does not allow mixing of IP versions * ``nonStrictCompare($address)`` allows mixing of IP versions, IPv4 ranges are "smaller" than IPv6 versions * ``compare($address, $strict = false)`` calls one of the above depending on $strict Ranges are compared first by base addresses, then by prefix lengths in natural order. ``127.0.0.0/8 < 192.168.0.0/16 < 192.168.0.0/24 < 192.168.1.0/24 < 255.0.0.0/8`` Returns one of ``[-1, 0, 1]`` like ``strcmp()`` or ``<=>``. :: compare($range1) > 0; // $range2 > $range1; true Equality -------- Also exists in 3 versions: * ``strictEquals($address)`` does not allow mixing of IP versions * ``nonStrictEquals($address)`` allows mixing of IP versions, IPv4 and IPv6 are never equal to each other * ``equals($address, $strict = false)`` calls one of the above depending on $strict Returns ``boolean``. :: equals($range2); // $range1 == $range2; false ``toString()`` -------------- Returns the canonical string representation of the IP range in CIDR notation:: toString(); // 127.0.0.0/8 Other getters ----------------- ``getBytes()`` Byte representation of the base address ``getPrefix()`` Prefix length ``getMaskBytes()`` Byte representation of the mask ``getMaskString()`` Mask value in the IP notation ``getFirstAddress()`` The first IP in the range, also its base address ``getLastAddress()`` The last IP in the range, the multicast address for the IPv4