承接 utopia-php/validators 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

utopia-php/validators

最新稳定版本:0.1.0

Composer 安装命令:

composer require utopia-php/validators

包简介

A lightweight collection of reusable validators for Utopia projects

README 文档

README

Reusable validation building blocks for Utopia projects.
This package exposes a consistent API for common HTTP-oriented validation concerns such as input sanitisation, URL checks, IP validation, hostname filtering, lists enforcement, and more.

Installation

composer require utopia-php/validators

Usage

use Utopia\Validator\Text;
use Utopia\Validator\Range;

$username = new Text(20, min: 3);
$age = new Range(min: 13, max: 120);

if (! $username->isValid($input['username'])) {
    throw new InvalidArgumentException($username->getDescription());
}

if (! $age->isValid($input['age'])) {
    throw new InvalidArgumentException($age->getDescription());
}

Validators expose a predictable contract:

  • isValid(mixed $value): bool – core validation rule
  • getDescription(): string – human readable rule summary
  • getType(): string – expected PHP type (string, integer, array, ...)
  • isArray(): bool – hint whether the validator expects an array input

For advanced flows combine validators with Multiple, AnyOf, AllOf, NoneOf, or wrap checks with helpers such as Nullable.

Available Validators

  • AllOf, AnyOf, NoneOf, Multiple – composition helpers
  • ArrayList, Assoc, Nullable, WhiteList, Wildcard
  • Boolean, Integer, FloatValidator, Numeric, Range
  • Domain, Host, Hostname, IP, URL
  • HexColor, JSON, Text

Development

Run the static analysis and test suites from the project root:

composer check
composer test

This project is released under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-20