nepada / email-address
Email address value object.
Installs: 29 612
Dependents: 2
Suggesters: 1
Security: 0
Stars: 6
Watchers: 4
Forks: 0
Open Issues: 0
Requires
- php: >=8.1.0 <8.5
- ext-intl: *
- ext-mbstring: *
- nette/utils: ^3.2@dev || ^4.0@dev
Requires (Dev)
- nepada/coding-standard: 7.14.0
- nepada/phpstan-nette-tester: 1.2.1
- nette/tester: v2.5.4
- php-parallel-lint/php-parallel-lint: 1.4.0
- phpstan/phpstan: 1.12.5
- phpstan/phpstan-nette: 1.3.8
- phpstan/phpstan-strict-rules: 1.6.1
- shipmonk/phpstan-rules: 3.2.0
- spaze/phpstan-disallowed-calls: 3.4.0
README
Installation
Via Composer:
$ composer require nepada/email-address
Usage
This package provides two implementations of email address value object:
RfcEmailAddress
- it adheres to RFCs and treats local part of email address as case sensitive. The domain part is normalized to lower case ASCII representation.CaseInsensitiveEmailAddress
- the only difference fromRfcEmailAddress
is that local part is considered case insensitive and normalized to lower case.
It is up to you to decide which implementation suites your needs. If you want to support both implementations, use Nepada\EmailAddress\EmailAddress
as a typehint. You can also cast one representation to the other using RfcEmailAddress::toCaseInsensitiveEmailAddress()
and CaseInsensitiveEmailAddress::toRfcEmailAddress()
.
Creating value object
$rfcEmailAddress = Nepada\EmailAddress\RfcEmailAddress::fromString('Real.example+suffix@HÁČKYčárky.cz'); $rfcEmailAddress = Nepada\EmailAddress\RfcEmailAddress::fromDomainAndLocalPart('HÁČKYčárky.cz', 'Real.example+suffix'); $ciEmailAddress = Nepada\EmailAddress\CaseInsensitiveEmailAddress::fromString('Real.example+suffix@HÁČKYčárky.cz'); $ciEmailAddress = Nepada\EmailAddress\CaseInsensitiveEmailAddress::fromDomainAndLocalPart('HÁČKYčárky.cz', 'Real.example+suffix');
Nepada\EmailAddress\InvalidEmailAddressException
is thrown in case of invalid input value.
Converting back to string
Casting the value object to string, will result in the original (non-canonical) string representation of email address:
echo((string) $emailAddress); // Real.example+suffix@HÁČKYčárky.cz echo($emailAddress->toString()); // Real.example+suffix@HÁČKYčárky.cz
Canonical string representation of email address
echo($emailAddress->getValue()); // real.example+suffix@xn--hkyrky-ptac70bc.cz
Getting normalized local and domain part separately
echo($emailAddress->getLocalPart()); // real.example+suffix echo($emailAddress->getDomain()); // xn--hkyrky-ptac70bc.cz
Integrations
- nepada/email-address-doctrine - Email address type for Doctrine.
- nepada/email-address-input - Email address form input for Nette forms.