定制 threeleaf/validation-engine 二次开发

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

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

threeleaf/validation-engine

Composer 安装命令:

composer require threeleaf/validation-engine

包简介

A Laravel Eloquent Model for managing dynamic validation engine rules.

README 文档

README

A Laravel library for managing dynamic validation rules and configurations.

Compatible with Laravel 12 and PHP 8.2+

Overview

The ValidationEngine library provides a robust solution for managing validation rules and configurations in a dynamic manner. It allows you to define validators that group multiple rules and apply them based on various criteria, such as time and status. This library is particularly useful for scenarios where validation logic needs to be customized or adjusted without directly modifying the codebase.

ValidationEngine

Latest Stable Version GitHub last commit Build Status Coverage PHP Version License Total Downloads

Installation

Install the library via Composer:

composer require threeleaf/validation-engine

Run the migrations to create the necessary tables:

php artisan migrate

Usage

Setting Up and Use Validators

To create a new validator and associate rules with it, use the Validator and Rule models:

use Illuminate\Container\Container;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator as LaravelValidator;
use Tests\Feature\TestCase;
use ThreeLeaf\ValidationEngine\Enums\ActiveStatus;
use ThreeLeaf\ValidationEngine\Models\Rule;
use ThreeLeaf\ValidationEngine\Models\Validator;
use ThreeLeaf\ValidationEngine\Models\ValidatorRule;
use ThreeLeaf\ValidationEngine\Rules\EnumRule;

/* Create a new validator */
$newValidator = Validator::create([
    'name' => 'StateAndTimeValidator',
    'description' => 'Validates state and checks time for Monday business hours.',
    'active_status' => ActiveStatus::ACTIVE,
]);

/* Create a rule */
$newRule = Rule::create([
    'attribute' => 'active_status',
    'rule_type' => EnumRule::class,
    'parameters' => json_encode([
        'enumClass' => 'ThreeLeaf\\ValidationEngine\\Enums\\ActiveStatus',
        'allowedValues' => [ActiveStatus::ACTIVE],
    ]),
]);

/* Associate the rule with the validator */
ValidatorRule::create([
    'validator_id' => $newValidator->validator_id,
    'rule_id' => $newRule->rule_id,
    'order_number' => 1,
    'active_status' => ActiveStatus::INACTIVE,
]);

/* Retrieve the validator */
$validator = Validator::where('name', 'StateAndTimeValidator')->first();

/* Extract the rule */
$rule = $validator->rules->first->get();

/* Retrieve the rule parameters */
$parameters = json_decode($rule->parameters, true);
$compiledRules = [
    $rule->attribute => [Container::getInstance()->makeWith(EnumRule::class, $parameters)],
];

/* Serialize the value you want to validate. */
$data = ['active_status' => ActiveStatus::ACTIVE->value];

/* Create the validator */
$validator = LaravelValidator::make($data, $compiledRules);

if ($validator->passes()) {
    Log::info('Success!');
}

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.

License

This library is open-sourced software licensed under the GPL-3.0+.

Miscellaneous

OpenApi Documentation

OpenAPI documentation can be generated within the application using the command:

php util/generate-swagger.php

Generate Coverage Badge

After running the tests with code coverage, run the following script to update the coverage badge:

php util/generate-coverage-badge.php

threeleaf/validation-engine 适用场景与选型建议

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

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

围绕 threeleaf/validation-engine 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2024-10-10