nordic/email-address
Composer 安装命令:
composer require nordic/email-address
包简介
Immutable Email Address value object
README 文档
README
This package represents an immutable email address value object and additional utility classes.
Install
Via Composer
$ composer require nordic/email-address
Features
- Immutable value object
- No dependencies
- Include null email address value object (see Null object pattern)
- Include assertion class
- Include factory class
Basic classes and interfaces
EmailAddressInterface - is the base interface for email address value objects.
EmailAddress - immutable email address value object that will be used most of the time.
NullEmailAddress - null email address value object (null object design pattern).
Usage
use Nordic\EmailAddress\EmailAddress; use Nordic\EmailAddress\NullEmailAddress; $emailAddress = new EmailAddress('email@example.com'); $nullEmailAddress = new NullEmailAddress; // Compare two email addresses $emailAddressSame = new EmailAddress('email@example.com'); $emailAddressAnother = new EmailAddress('another@example.com'); var_dump($emailAddress->equals($emailAddressSame)); // boolean(true) var_dump($emailAddress->equals($emailAddressAnother)); // boolean(false)
Exceptions
InvalidEmailAddressException - is a basic exception that you can use. The first argument is a string value.
use Nordic\EmailAddress\InvalidEmailAddressException; $e = new InvalidEmailAddressException('wrong_email', 'Wrong email address'); var_dump($e->getEmailAddress()); // string(17) "wrong_email"
Factory pattern
EmailAddressFactoryInterface - is the base interface for email address factory.
EmailAddressFactory - is the factory class that creates EmailAddress value objects.
use Nordic\EmailAddress\EmailAddressFactory; $factory = new EmailAddressFactory; $emailAddress = $factory->createEmailAddress('email@example.com'); $nullEmailAddress = $factory->createEmailAddress(); $emailAddress = $factory->createEmailAddress('wrong_email'); // will throw InvalidEmailAddressException
Assertion
The class Assertion can be used for checking if string value is an email address string or check if email address value object is not null object. All methods will throw InvalidEmailAddressException if assertion will fails. You can always set a custom exception message as the second method argument.
Available methods:
Assertion::email- will fail in case if string value is not a valid email address.Assertion::notNull- will fail in case if email address value object is null email address object.
use Nordic\EmailAddress\Assertion; $email = Assertion::email('email@example.com'); $email = Assertion::email('wrong_email'); // will throw InvalidEmailAddressException $emailAddress = Assertion::notNull($emailAddress); // will throw InvalidEmailAddressException if $emailAddress is instance of NullEmailAddress
Additional helpers
Provider interface and trait
Use interface EmailAddressProviderInterface and trait EmailAddressProviderTrait when the object should only provide email address value object (see EmailAddressProviderTest.php for examples).
Aware intrerface and trait
Use interface EmailAddressAwareInterface and trait EmailAddressAwareTrait when the object should aware about email address value object (see EmailAddressAwareTest.php for examples).
Example
use Nordic\EmailAddress\Assertion; use Nordic\EmailAddress\EmailAddress; use Nordic\EmailAddress\EmailAddressInterface; use Nordic\EmailAddress\EmailAddressFactory; use Nordic\EmailAddress\InvalidEmailAddressException; use Nordic\EmailAddress\EmailAddressProviderInterface; use Nordic\EmailAddress\EmailAddressProviderTrait; class MyClass implements EmailAddressProviderInterface { use EmailAddressProviderTrait; public function __construct(EmailAddressInterface $emailAddress) { $this->emailAddress = Assertion::notNull($emailAddress); } } $factory = new EmailAddressFactory; try { $myClass = new MyClass($factory->createEmailAddress('email@example.com')); } catch (InvalidEmailAddressException $e) { // do something } $emailAddress = $myClass->getEmailAddress();
Testing
$ composer test
Credits
License
The MIT License (MIT). Please see License File for more information.
nordic/email-address 适用场景与选型建议
nordic/email-address 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 05 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「email」 「Value Object」 「email address」 「immutable」 「nordic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nordic/email-address 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nordic/email-address 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nordic/email-address 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Runn Me! Value Objects Library
Laravel SDK mapping data in object
MaxAl Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
Rinvex Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
Provides Symfony param converters for mediagone/types-common package.
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-01