componenta/email
Composer 安装命令:
composer require componenta/email
包简介
Email value object
README 文档
README
Immutable email address value object with validation, normalization, masking, domain helpers, and JSON/string serialization.
Use it at application boundaries where a validated email address should be represented as a typed value instead of a raw string.
Installation
composer require componenta/email
Requires the mbstring extension.
Related Packages
This package validates email values without neighboring Componenta packages.
| Package | Why it may be used nearby |
|---|---|
componenta/validation |
Validates user input before creating Email. |
componenta/auth |
Can use email for login, password reset, or magic-link flows. |
componenta/cqrs |
Commands can type email fields with this value object. |
Usage
use Componenta\Stdlib\Email; $email = Email::fromString('Ada@Example.COM'); (string) $email; // "ada@example.com" $email->local; // "ada" $email->domain; // "example.com" $email->isFromDomain('example.com'); // true $email->masked(); // "ad*@example.com"
Validation
new Email() and Email::fromString() throw InvalidArgumentException when:
- the address is empty
- the address is not accepted by
FILTER_VALIDATE_EMAIL - the full address exceeds 254 characters
- the local part exceeds 64 characters
- the domain exceeds 253 characters
Use Email::tryFromString() when invalid input should produce null.
Normalization
The constructor trims whitespace, removes invisible control characters, and lowercases both local and domain parts. The stored value, __toString(), and jsonSerialize() all return the normalized address.
Helpers
equals()compares normalized addressestld()returns the last domain segmentisFromDomain()performs case-insensitive domain comparisonmasked()returns a log/UI-safe representation
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-14