php-dto/ip-address

Immutable ip object with validation and helpful methods

Installs: 13

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

pkg:composer/php-dto/ip-address

0.1.0 2023-08-29 23:47 UTC

This package is not auto-updated.

Last update: 2025-10-23 09:28:32 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)