php-dto/ip-address

Immutable ip object with validation and helpful methods

0.1.0 2023-08-29 23:47 UTC

This package is not auto-updated.

Last update: 2024-11-07 04:35:37 UTC


README

Installation

composer require php-dto/ip-address

Usage

<?php
use \PhpDto\EmailAddress\EmailAddress;
use \PhpDto\EmailAddress\Exception\InvalidIpAddressException;

$ip = new IpAddress('192.168.1.1'); //spaces will be trimmed

echo $ip->get();              //will print '192.168.1.1'
echo (string) $ip;            //will print '192.168.1.1'
echo json_encode([$ip]);      //will print '["192.168.1.1"]'


new IpAddress('invalid.value'); //will throw InvalidIpAddressException (validate by FILTER_VALIDATE_IP)