atournayre/types
Lightweight PHP library providing reusable types/value objects. Installable via Composer, intended to standardize and validate common domain data. Open-source on GitHub with issue tracker and MIT license.
EmailAddress type introduces specialized email validation (e.g., RFC compliance, disposable domain checks), addressing a critical gap in Laravel/PHP ecosystems where email validation is often handled ad-hoc (e.g., Str::of($email)->contains('@')). This aligns with:
Validator::make()->email() with stricter rules (e.g., rejecting user@example or user@disposable.com).UserType::email).EmailAddress::fromString($raw)).Validator::email() with Type::email()->validate($request->email).protected $emailType = EmailAddress::class).EmailAddress constraints.EmailAddress::fromRequest()).laravel-shift/email-verification.user@{$dynamicDomain}.com) may conflict with strict typing.| Risk Area | Mitigation Strategy |
|---|---|
| False Positives | Combine with Laravel’s Validator (e.g., Type::email()->validate() + Rule::unique()). |
| Performance | Cache EmailAddress validation results for bulk operations (e.g., user imports). |
| Adoption Resistance | Pilot in registration/login flows where email validation is critical. |
| Maintenance | Monitor for updates to RFC standards or disposable email lists. |
EmailAddress support custom disposable domain lists (e.g., temp-mail.org) or rely on a third-party API?HasEmailVerification trait for seamless email validation + verification?egulias/email-validator)?EmailAddress be serialized/deserialized (e.g., for API responses or database storage)?EmailAddress.FormRequest with typed email validation.EmailAddress to model casts or accessors.UserResource::email()).Symfony\Component\Validator\Constraints\Email.Validator::email() with Type::email()->validate() in controllers.use Type\EmailAddress;
public function store(Request $request) {
$email = EmailAddress::validate($request->email); // Throws on failure
// Proceed with typed $email
}
EmailAddress to model casts or accessors:
protected $casts = [
'email' => EmailAddress::class,
];
EmailAddress in services/repositories (e.g., UserService::create(EmailAddress $email)).Mailable classes.Illuminate\Auth\Passwords\PasswordBroker.| Priority | Component | Integration Strategy |
|---|---|---|
| High | Registration/Login | Replace Validator::email() with EmailAddress::validate(). |
| Medium | Eloquent Models | Add EmailAddress casts/accessors. |
| Low | Legacy Dynamic Code | Isolate in non-critical paths (e.g., admin panels). |
| Future | Real-time Features | Livewire/Inertia form submissions with typed email validation. |
@, disposable domains).EmailAddress.EmailAddress with custom rules (e.g., EmailAddress::companyDomain('acme.com')).user@example").EmailAddress::tryValidate($email)).egulias/email-validator if needed.EmailAddress instances in memory (e.g., Redis).| Scenario | Impact | Mitigation |
|---|---|---|
| Strict Validation Fails | Rejected valid emails (e.g., user+tag@example.com). |
Whitelist edge cases or use EmailAddress::looseValidate(). |
| Disposable List Stale | False positives (e.g., user@temp-mail.org accepted). |
Update disposable domain lists manually or integrate with a paid API. |
| Over-Typing | Excessive boilerplate for simple emails. | Reserve for critical paths (e.g., user auth); use dynamic for internal. |
| Tooling Conflicts | PHPStan false positives. | Configure tooling to ignore EmailAddress or extend its rules. |
EmailAddress vs. Validator::email().EmailAddress::tryValidate($email) with fallback to filter_var($email, FILTER_VALIDATE_EMAIL).How can I help you explore Laravel packages today?