Download the PHP package luka/network-address-types without Composer
On this page you can find all versions of the php package luka/network-address-types. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download luka/network-address-types
More information about luka/network-address-types
Files in luka/network-address-types
Package network-address-types
Short Description Provides typed value objects for network addresses (IP v4/v6 and MAC)
License LGPL-3.0
Informations about the package network-address-types
Network Address Types for PHP
This library provides types to handle the most common network addresses. The following address types are supported:
- MAC addresses in the following forms:
- Colon separated (
00:00:00:00:00:00
) - Dash separated (
00-00-00-00-00-00
) - Without separator (
000000000000
)
- Colon separated (
- IPv4 (ex:
127.0.0.1
) - IPv6 (ex:
::1
) - CIDR addresses for IPv4 and IPv6 (ex:
129.0.0.1/12
,ff80:e::/64
)
Installation
Installation can be performed with composer:
Requirements
- PHP
- 7.4 (until version 1.1.0)
- 8.0
- 8.1
- 8.2
ext-gmp
for handling IPv6 calculationsext-json
as it supports json_encode by implementingJSONSerializable
Getting started
Serialization
All types can be constructed from strings and can therefore be converted
to strings as well with the toString()
method.
When converting addresses to strings, they will be normalized for the corresponding type:
JSON
All address types implement the JSONSerializable
interface, and can therefore be used with
json_encode()
directly.
Binary
IP and MAC addresses can also be converted to the corresponding byte sequence. (for example to storing them in
a BINARY
database field).
They can also be constructed from this byte sequence with the static fromByteString()
method of the corresponding
class.
Address Comparison
Compare equality
Each address implements an equals()
method to compare it to other
network addresses.
Addresses are considered equal when they are from the same type and contain the same value:
Comparing addresses to networks
CIDR addresses allow to obtain the corresponding network to the denoted address. With this network you can check if an IP address is within this network.
This will work for IPv6 as well:
All versions of network-address-types with dependencies
ext-gmp Version *
ext-json Version *