imliam/php-unique-gmail-address
Composer 安装命令:
composer require imliam/php-unique-gmail-address
包简介
Ensure that a Gmail address is unique
README 文档
README
A package to ensure that a Gmail address is unique.
The Gmail platform offers some features that other email platforms don't. There can be an infinite number of different Gmail addresses that point to a single Gmail inbox/account, which can make it very easy for malicious users to abuse with no effort.
To learn more about how a user can make a infinite addresses for one Gmail inbox, check out this article.
This package makes it possible to detect duplicate addresses for one Gmail account and to ensure they're unique.
Installation
You can install the package via composer:
composer require imliam/php-unique-gmail-address
Usage
The primary usage of this package revolves around the supplied UniqueGmailAddress class, which can be passed an email address to compare:
$email = new UniqueGmailAddress('example@gmail.com');
The isGmailAddress method will check if the given address belongs to a Gmail account:
$one = new UniqueGmailAddress('example@gmail.com'); $one->isGmailAddress(); // true $two = new UniqueGmailAddress('example@googlemail.com'); $two->isGmailAddress(); // true $three = new UniqueGmailAddress('example@example.com'); $three->isGmailAddress(); // false
The normalizeAddress method will take an email address and normalize it to the simplest variation:
$email = new UniqueGmailAddress('ex.am.ple+helloworld@googlemail.com'); $email->normalizeAddress(); // example@gmail.com
⚠️ It's best to save and use the email address exactly as the user gave instead of only saving a normalized version. If a user enters a denormalized email address, they probably expect any emails they receive to be at that exact address and not the normalized version.
The getRegex and getRegexWithDelimeters methods will return a regular expression that can be used to compare the original email address to another one, using a function like preg_match:
$email = new UniqueGmailAddress('example@gmail.com'); $email->getRegex(); // ^e(\.?)+x(\.?)+a(\.?)+m(\.?)+p(\.?)+l(\.?)+e(\+.*)?\@(gmail|googlemail).com$
The matches method will immediately match the regular expression against another value, returning true if both email addresses belong to the same Gmail account:
$email = new UniqueGmailAddress('example@gmail.com'); $email->matches('ex.am.ple+helloworld@googlemail.com'); // true
Laravel Rule
One of the most common use cases for wanting to check duplicate Gmail accounts is to prevent multiple users signing up to your service with the same email address.
To handle this case, the package also provides a Laravel validation rule class that can be used to check the database if a matching email address is already present.
$request->validate([ 'email' => [new UniqueGmailAddressRule()], ]);
By default, it will check the email column in the users table, but these can be overriden if needed when using the rule:
$request->validate([ 'email' => [new UniqueGmailAddressRule('contacts', 'email_address')], ]);
This rule assumes that you are storing denormalized email addresses in the database. This rule will use a regex match against every row in the database to check if
💡 If you don't want to use a regex match against every row of the database, you could instead store the normalized email address in a second column alongside the original email address, for example in a
normalized_emailcolumn.This would allow you use the regular exists rule to do a direct match against, much more efficiently.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email liam@liamhammett.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
imliam/php-unique-gmail-address 适用场景与选型建议
imliam/php-unique-gmail-address 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.91k 次下载、GitHub Stars 达 91, 最近一次更新时间为 2020 年 09 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「imliam」 「php-unique-gmail-address」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 imliam/php-unique-gmail-address 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 imliam/php-unique-gmail-address 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 imliam/php-unique-gmail-address 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An easier way to define custom Blade directives.
Utility class to validate, format and generate NHS numbers.
Utility class to validate, format and generate NHS numbers.
Set a .env file variable from the command line
Present names for English-language applications.
Gracefully handle an unwanted exit statement.
统计信息
- 总下载量: 4.91k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 91
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-09-12