hybridmind/validate
最新稳定版本:1.0.0
Composer 安装命令:
composer require hybridmind/validate
包简介
A robust and flexible validation library for PHP.
README 文档
README
The Validate class offers a robust and flexible way to handle validation logic in your PHP applications. This class simplifies and centralizes validation rules, making your code cleaner and more maintainable.
Features
- Simplified Code: Reduce boilerplate and repetitive validation logic.
- Centralized Validation Rules: Manage all your validation logic in one place.
- Improved Readability: Declarative syntax for clearer, more maintainable code.
- Extensible: Easily add new validation rules as needed.
Before and After
Before Manual validation logic often leads to repetitive code:
if (empty($_POST['username'])) { $errors[] = 'Username is required.'; } elseif (strlen($_POST['username']) < 3) { $errors[] = 'Username must be at least 3 characters long.'; } elseif (strlen($_POST['username']) > 20) { $errors[] = 'Username cannot exceed 20 characters.'; }
After Using the Validate class streamlines the process:
$validate = new Validate(); $validationResult = $validate->check($_POST, [ 'username' => [ Validate::REQUIRED => ['message' => 'Username is required.'], Validate::MIN => ['min' => 3, 'message' => 'Username must be at least 3 characters long.'], Validate::MAX => ['max' => 20, 'message' => 'Username cannot exceed 20 characters.'], ], ]); if ($validate->isValid()) { // Proceed with processing } else { $errors = $validate->getErrors(); // Handle validation errors }
Installation
To use the Validate class, simply include the class file in your project.
composer require hybridmind/validate
Contributing
We welcome contributions to enhance the Validate class. To contribute, please follow these steps:
- Fork the repository.
- Create a new branch.
- Make your changes and commit them with clear and descriptive messages.
- Push your changes to the branch.
- Submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-05