定制 oihana/php-validation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

oihana/php-validation

Composer 安装命令:

composer require oihana/php-validation

包简介

The Oihana PHP Validation library

README 文档

README

Oihana PHP Validation

Composable validation rules and helpers for PHP 8.4+, built on Somnambulist Validation.

Latest Version
Total Downloads
License

📚 Documentation

User guides (FR + EN), with narrative explanations and examples:

🇬🇧 English documentation 🇫🇷 Documentation française
Getting started, rules, helpers, ISO 8601, geo & i18n, model-aware rules, custom rules, testing. Démarrage, règles, helpers, ISO 8601, géo & i18n, règles liées aux modèles, règles sur mesure, tests.

Auto-generated API reference (phpDocumentor):
👉 https://bcommebois.github.io/oihana-php-validation

🧠 What is it?

This package extends Somnambulist Validation with a curated set of reusable, strongly-typed rules and expressive helper functions. Each rule is a small, focused, tested class you register with the validation factory; each helper builds a rule expression string fluently.

use Somnambulist\Components\Validation\Factory;
use oihana\validations\rules\ISO8601DateRule;

use function oihana\validations\rules\helpers\between;

$factory = new Factory();
$factory->addRule( 'iso8601_date', new ISO8601DateRule() );

$validation = $factory->validate
(
    [ 'birthDate' => '1990-05-01', 'age' => 34 ],
    [
        'birthDate' => 'required|iso8601_date',
        'age'       => 'required|' . between( 0, 120 ), // "between:0,120"
    ]
);

$validation->passes(); // true

🚀 Features

  • 🔢 Comparison & range rules — EqualRule, GreaterThanRule, LessThanRule, RangeRule.
  • 📅 ISO 8601 date, datetime & duration rules — ISO8601DateRule, ISO8601DateTimeRule, ISO8601DurationRule.
  • 🌍 Geo & i18n rules — LatitudeRule, LongitudeRule, ElevationRule, I18nRule, PostalCodeRule.
  • 🗄️ Model-aware rules — ExistModelRule, UniqueModelRule, ConstantsRule.
  • 🔐 Auth rules — EffectRule, JWTAlgorithmRule; HTTP — HttpMethodRule.
  • 🧰 Expressive rule helpers — between(), requiredIf(), digitsBetween(), arrayMustHaveKeys(), and more.
  • 🧪 Full unit-test coverage ensuring reliability and maintainability.

💡 Designed to be lightweight, testable, and compatible with any PHP 8.4+ project.

📦 Installation

Requires PHP 8.4+

Install via Composer:

composer require oihana/php-validation

✅ Tests & coverage

Run the full unit-test suite (PHPUnit, strict mode):

composer test

Run a single test case:

./vendor/bin/phpunit --filter ISO8601DateRuleTest

Measure coverage (requires Xdebug or PCOV):

composer coverage        # text + Clover + HTML under build/coverage/
composer coverage:md     # readable Markdown summary (build/coverage/COVERAGE.md)

The suite runs in strict mode and targets 100% line coverage.

🧾 License

This project is licensed under the Mozilla Public License 2.0 (MPL-2.0).

👤 About the author

🛠️ Generate the Documentation

We use phpDocumentor to generate the documentation into the ./docs folder.

Usage

Run the command :

composer doc

🔗 Related packages

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MPL-2.0
  • 更新时间: 2026-06-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固