bacarin/heimdall-validator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

bacarin/heimdall-validator

Composer 安装命令:

composer require bacarin/heimdall-validator

包简介

A pure PHP validation package inspired in Laravel way to validate data. Made in raw PHP without any dependency.

README 文档

README

Prevent unwanted data in your project with Heimdall Validator.

Heimdall Validator was inspired by Laravel and Symfony validators. It receives an associative array with data and another associative array with the desired validation rules.

This package does not throw exceptions or block any request. Instead, it returns a Heimdall object that lets you check validation results using $validate->passes() or $validate->fails(), and access detailed error messages with $validate->errors(). Examples are provided below.

Index

Requirements

  • PHP 7.0+ (not tested on older versions)
  • No external dependencies. Built with pure PHP to avoid dependency issues and to be compatible with older PHP versions.

Installation

You can install using Composer by running the command below:

NOT AVAILABLE YET

composer install bacarin/heimdall-validator

How to Use

After installation, import the Bacarin\Heimdall class and call the static validate method, passing the validation rules and the data to validate, like this:

use Bacarin\Heimdall;

function yourFunc(){
    $data = [
		'name' => 'John Doe',
		'age' => 18
	];
    $rules = [
		'name' => 'required|string|min:3',
		'age' => 'required|integer|max:80'
	];
    $validation = Heimdall::validate($rules, $data);
	if ($validation->passes()){
		... your code here
	}
}

Available Methods

$validate->passes()

Returns a boolean indicating whether the payload is valid. Returns true if valid, false otherwise.

$validate->fails()

Returns a boolean indicating whether the payload is invalid. Returns true if invalid, false otherwi

$validate->errors()

Returns an associative array containing validation error messages. If empty, the payload is valid. Exampĺe:

[
	"access_level" => [
		"The field access_level is prohibited when role is in [admin, manager]."
	]
]

Available Rules

More rules will be added in future releases or upon request.

Rule Description Parameters Example
accepted_if Must be 'yes', 'on', '1', 1, true, or 'true' if another field has a specific value field,value accepted_if:status,active
accepted Must be 'yes', 'on', '1', 1, true, or 'true' accepted
after_or_equal Must be a date/datetime after or equal to a given date, or 'today', 'tomorrow', 'yesterday' date after_or_equal:today, after_or_equal:2025-10-10
after Must be a date/datetime after a given date, or 'today', 'tomorrow', 'yesterday' date after:yesterday, after:2025-09-09
array Must be an array array
before_or_equal Must be a date/datetime before or equal to a given date, or 'today', 'tomorrow', 'yesterday' date before_or_equal:today, before_or_equal:2025-10-10
before Must be a date/datetime before a given date, or 'today', 'tomorrow', 'yesterday' date before:today, before:2025-10-10
boolean Must be a boolean: true, false, 1, 0, 'true', or 'false' boolean
date Must be a valid date. Can also validate a specific format ?format date, date:Y-m-d
datetime Must be a valid datetime. Can also validate a specific format ?format datetime, datetime:d/m/Y H:i
declined_if Must be 'no', 'off', '0', 0, false, or 'false' if another field has a specific value field,value declined_if:status,inactive
declined Must be 'no', 'off', '0', 0, false, or 'false' declined
email Must be a valid email address email
gte Must be a number greater than or equal to a given value value gte:18
gt Must be a number greater than a given value value gt:17
in Must be one of the specified values value in:paid,nonpaid,overdue,canceled
integer Must be an integer integer
lte Must be a number less than or equal to a given value value lte:80
lt Must be a number less than a given value value lt:81
max Maximum value for numbers or maximum length for strings value max:100
min Minimum value for numbers or minimum length for strings value min:3
nullable Field can be null nullable
prohibited_with Field is prohibited if another field is present field prohibited_with:company_name
prohibited_if Field is prohibited if another field has a specific value field,value prohibited_if:role,user
prohibited_if_in Field is prohibited if another field has one of the specified values field,value,value... prohibited_if_in:role,admin,manager
regex Must match the given regular expression value regex:^[a-z0-9]+$
required_if_in Required if another field has one of the specified values field,value,value... required_if_in:status,active,pending
required_if Required if another field has a specific value field,value required_if:status,active
required_with Required if another field is present field required_with:name
required Field is required required
sometimes Field is validated only if it is present sometimes
string Must be a string string
uuid Must be a valid UUID. Can specify the UUID version ?value uuid, uuid:4
-------------------- ---------------------------------------------------------------------------------------------- ---------------------- -------------------------------------------------------

bacarin/heimdall-validator 适用场景与选型建议

bacarin/heimdall-validator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 bacarin/heimdall-validator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bacarin/heimdall-validator 我们能提供哪些服务?
定制开发 / 二次开发

基于 bacarin/heimdall-validator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: ISC
  • 更新时间: 2025-08-13