php-dto / email-address
Immutable email object with validation and helpful methods
Installs: 3 719
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.2.0
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-04 06:17:57 UTC
README
Installation
composer require php-dto/email-address
Usage
<?php use \PhpDto\EmailAddress\EmailAddress; use \PhpDto\EmailAddress\Exception\InvalidEmailAddressException; $email = new EmailAddress(' mail@example.com '); //spaces will be trimmed echo $email->get(); //will print 'mail@example.com' echo (string) $email; //will print 'mail@example.com' echo $email->getUsername(); //will print 'mail' echo $email->getHostname(); //will print 'example.com' echo json_encode([$email]); //will print '["mail@example.com"]' new EmailAddress('example.com'); //will throw InvalidEmailAddressException (validate by FILTER_VALIDATE_EMAIL)