qdenka/easyvalidation
Composer 安装命令:
composer require qdenka/easyvalidation
包简介
EasyValidation — a package for simple, fast, and extendable data validation (email, URL, number, date, credit card, IP, phone, etc.).
README 文档
README
EasyValidation is a lightweight PHP library for validating common data types. Built with DDD, SOLID, and DRY principles, it offers both a factory-based API and convenient static helper methods.
📋 Table of Contents
✨ Features
- ✅ Validate emails (standard, Gmail-only, disposable)
- ✅ Validate URLs, numbers, dates
- ✅ Validate IPs (IPv4 & IPv6)
- ✅ Validate UUIDs (v1–v5)
- ✅ Validate JSON and Base64 strings
- ✅ Validate international phone numbers (E.164)
- 📦 PSR-4 autoloading
- 🔄 Factory-based API + static helpers
- ⚙️ Easily extendable with new validators
⚙️ Requirements
- PHP ^7.4 || ^8.0
🚀 Installation
Install with Composer:
composer require qdenka/easyvalidation
Autoloading is configured via PSR-4 (QDenka\EasyValidation\).
🛠️ Usage
Factory API
Use ValidatorFactory to retrieve any validator by its type key:
use QDenka\EasyValidation\Application\Validators\ValidatorFactory; $types = ['email','google_email','disposable_email','url','number','date','ip','uuid','json','base64','phone']; foreach ($types as $type) { $validator = ValidatorFactory::create($type); $value = 'test_value_for_' . $type; if ($validator && $validator->validate($value)) { echo "[$type] valid\n"; } else { echo "[$type] invalid\n"; } }
Static Helpers
For quick checks, use the Validator facade:
use QDenka\EasyValidation\Infrastructure\Factories\Validator; if (Validator::isValidEmail('user@example.com')) { echo "Valid email"; } if (Validator::isGoogleMail('user@gmail.com')) { echo "It's a Gmail address"; } if (Validator::isDisposableEmail('temp@mailinator.com')) { echo "Disposable email detected"; } // Other helpers: Validator::isValidUrl('https://example.com'); Validator::isValidNumber('123.45'); Validator::isValidDate('2023-04-23'); Validator::isValidIp('2001:db8::1'); Validator::isValidUuid('550e8400-e29b-41d4-a716-446655440000'); Validator::isValidJson('{"foo":1}'); Validator::isValidBase64(base64_encode('hello')); Validator::isValidPhone('+1234567890');
📑 Available Validators
| Type | Static Helper | Description |
|---|---|---|
email |
isValidEmail() |
RFC-compliant email |
google_email |
isGoogleMail() |
Gmail & Googlemail domains |
disposable_email |
isDisposableEmail() |
Blacklisted disposable domains |
url |
isValidUrl() |
HTTP/HTTPS URLs |
number |
isValidNumber() |
Numeric values |
date |
isValidDate() |
Date in Y-m-d (configurable format) |
ip |
isValidIp() |
IPv4 & IPv6 addresses |
uuid |
isValidUuid() |
UUID v1–v5 |
json |
isValidJson() |
JSON string parsing |
base64 |
isValidBase64() |
Base64-encoded data |
phone |
isValidPhone() |
International E.164 phone numbers |
⚙️ Configuration
Disposable Domains List
Customize disposable email domains by editing config/disposable_domains.php:
return [ 'mailinator.com', '10minutemail.com', // add your domains here ];
Ensure all domains are lowercase.
🧩 Extending
To add a new validator:
- Implement
ValidatorInterfaceinsrc/Domain/YourType/YourValidator.php. - Register your class in
ValidatorFactory(src/Application/Validators/ValidatorFactory.php). - (Optional) Add a static helper in
Validatorfacade (src/Infrastructure/Factories/Validator.php). - Write tests under
tests/following existing patterns.
🧪 Testing
Run PHPUnit:
vendor/bin/phpunit --colors
All tests must pass before merging.
🤝 Contributing
- Fork repository
- Create a feature branch (
git checkout -b feature/NewValidator) - Commit changes (
git commit -m 'Add NewValidator') - Push (
git push origin feature/NewValidator) - Open a Pull Request
Follow PSR-12 coding standards and include tests.
📄 License
This project is licensed under the MIT License. See LICENSE for details.
qdenka/easyvalidation 适用场景与选型建议
qdenka/easyvalidation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「email」 「url」 「date」 「validation」 「number」 「phone」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 qdenka/easyvalidation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 qdenka/easyvalidation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 qdenka/easyvalidation 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tools to convert between .NET and PHP date formats
Easy URL rewrites in your Laravel application
A powerful event calendar Tool for Laravel's Nova 5.
Date component is a set of methods to help with the manipulation of dates.
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
A Laravel helper to detect if the current route/path is active.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-23