escuelait/magnific-validator
Composer 安装命令:
composer require escuelait/magnific-validator
包简介
PHP Validation Library
README 文档
README
MagnificValidator is a small yet powerful validation library for PHP. Inspired by Laravel’s validation style, it allows you to validate input data using simple, expressive rule definitions.
🚀 Installation
Install the package via Composer:
composer require escuelait/magnific-validator
✨ Features
-
Validate single values or full data arrays
-
Built-in support for common rules:
requiredemailurlmax:<value>
-
Retrieve detailed error messages after validation
-
Throw exception on unknown rules
-
Easy to extend with custom rule classes
🧪 Basic Usage
use Escuelait\MagnificValidator\Validator; $validatorFactory = new ValidatorsFactory(); // Validador de formulario $validator = $validatorFactory->create([ 'email' => ['required', 'email'], 'password' => ['required', 'max:16'], ]); $errors = $validator->validate([ 'email' => 'user@example.com', 'password' => 'secret123', ]); if (empty($errors)) { echo "Valid data!"; } else { echo "Has validation errors:\n"; print_r($errors); } // Validador de un campo $validator = $validatorFactory->create(['required', 'email']); $errors = $validator->validate('user@example.com'); if (empty($errors)) { echo "Valid data!"; } else { echo "Has validation errors:\n"; print_r($errors); } // Validador de una regla simple $validator = $validatorFactory->create('email'); $errors = $validator->validate('user@example.com'); if (empty($errors)) { echo "Valid data!"; } else { echo "Has validation errors:\n"; print_r($errors); }
✅ Available Rules
| Rule | Description |
|---|---|
required |
The value must not be empty |
email |
Must be a valid email address |
url |
Must be a valid URL |
max:<n> |
Maximum number of characters (or numeric value) |
⚠️ If you use an unsupported rule, an
InvalidArgumentExceptionwill be thrown.
✅ Example Test Cases
MagnificValidator includes a test suite using PHPUnit with various validation scenarios.
Valid inputs
['miguel@escuela.it', ['email']], ['https://escuela.it', ['url', 'required']], ['Valid text', ['required', 'max:40']],
Invalid inputs
['', ['required']], // Missing required input ['invalid_email', ['email']], ['http:/bad-url', ['url']], ['Too long text...', ['max:10']],
🧪 Running Tests
Run the test suite using PHPUnit:
vendor/bin/phpunit
🧩 Custom Rules
You can extend the validator by creating your own rules. Just implement a rule class and ensure it returns a validate() method and a message() method.
📦 Contributions
Feel free to open issues or submit pull requests. We welcome contributions to improve the validator or add new rules.
📝 License
MIT License © EscuelaIT
escuelait/magnific-validator 适用场景与选型建议
escuelait/magnific-validator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 escuelait/magnific-validator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 escuelait/magnific-validator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-27