christianberkman/codeigniter4-date-validation
Composer 安装命令:
composer require christianberkman/codeigniter4-date-validation
包简介
Custom validation library for the CodeIgnitor4 framework to validate and compare dates
README 文档
README
Custom validation library for the CodeIgniter4 framework to validate and compare dates.
To Do
- Add rules:
- Use CodeIgniter4 coding standard library
- Create unit tests
- Use languae files for errors
Installation
Installation via composer:
composer require christianberkman/codeigniter4-date-validation
If auto discovery in your CodeIgniter app is enabled, the library will be discovered automatically.
Manual installation
Copy src/DateValidation.php to app/ThirdParty, adjust namespace and register in app/Config/Validation.php
Usage
The library offers rules for validating the value date to today or another field. All rules also validate the date so the built-in valid_date rule does not need to be called.
// any date before today's date
date_before_today[Y-m-d]
// any on or after a given field date
date_starting[date_arrival,Y-m-d]
// any date on Monday (1) or Wednesday (3)
date_on_dow[Y-m-d,1,3]
Date Format
When comparing the value date to a field date, both dates are assumed to be in the same format. All format parameters are optional. If the format paremeter is specified, the dates will be creaed using DateTime::createFromFormat. If the format paremeter is omitted, the date is created using strtotime(). It is reccommended to always specify a format.
Exception: The format parameter is required for the date_on_dow rule, 'none' can be specified if you wish to not specify any format: 'today' -> date_on_dow[none,1]
Time information
All time information is discarded, all times will be set to 00:00:00 UTC.
Errors
Errors are dynamically returned by each rule, e.g. Date must be before last_available_date field.
Available Rules
| Rule | Parameters | Discription | Example |
|---|---|---|---|
| date_before_today | format | Validates if the value date is before today | date_before_today[Y-m-d] |
| date_ending_today | format | Validates if the value date is on or before today | date_ending_today[Y-m-d] |
| date_starting_today | format | Validates if the value date is on or after today | date_starting_today[Y-m-d] |
| date_after_today | format | Validates if the value date is after today | date_after_todat[Y-m-d] |
| date_before | field, format | Validates if the value date is before a field date | date_before[departure_date,Y-m-d] |
| date_ending | field, format | Validates if the value date is on or before a field date | date_ending[departure_date,Y-m-d] |
| date_starting | field, format | Validates if the value date is on or after a field date | date_starting[arrival_date,Y-m-d] |
| date_after | field, format | Validates if the value date is after a field date | date_after[date_of_birth,Y-m-d] |
| date_on_dow | format, days of week | Validates if the value date is on a given day of week starting Monday (1-7) | date_on_dow[Y-m-d,1,2,3,4,5] |
Full Example
$data = [ 'arrival_date' => '2024-07-01', 'excursion_date' => '2024-07-03', 'depatrue_date' => '2024-07-10', 'last_available_date' => '2027-08-09', ]; $rules = [ // arrival needs to be at earliest tomorrow 'arrival_date' => 'date_after_today', // excursion needs to be between (and not on) departure and arrival 'excursion_date' => 'date_after[arrival_date,Y-m-d]|date_before[depatrue_date,Y-m-d]', // departure needs to be after (and not on) the arrival date and before (and not on) the last available date 'departure_date' => 'date_after[arrival_date,Y-m-d]|date_before[last_available_Date]', ]; $validation = $this->validateData($data, $rules); // returns false $errors = $this->validator->getErrors(); /** * Result: * 'departure_date' => 'Date must be before last_available_date field' */
christianberkman/codeigniter4-date-validation 适用场景与选型建议
christianberkman/codeigniter4-date-validation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 06 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 christianberkman/codeigniter4-date-validation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 christianberkman/codeigniter4-date-validation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-26