vjik/yii-validator-symfony-rule 问题修复 & 功能扩展

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

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

vjik/yii-validator-symfony-rule

最新稳定版本:1.0.0

Composer 安装命令:

composer require vjik/yii-validator-symfony-rule

包简介

Symfony validation constraints adapter for Yii Validator

README 文档

README

     

Yii Validator Symfony Rule


Latest Stable Version Total Downloads Build status Mutation testing badge type-coverage static analysis psalm-level

The package provides validator rule SymfonyRule that allow use Symfony validation constraints in Yii Validator.

Requirements

  • PHP 8.0 or higher.

Installation

The package could be installed with composer:

composer require vjik/yii-validator-symfony-rule

General usage

Wrap a symfony constraints to Yii rule SymfonyRule enough. For example:

use Symfony\Component\Validator\Constraints\CssColor;
use Symfony\Component\Validator\Constraints\NotEqualTo;
use Symfony\Component\Validator\Constraints\Positive;
use Vjik\Yii\ValidatorSymfonyRule\SymfonyRule;
use Yiisoft\Validator\Rule\HasLength;
use Yiisoft\Validator\Rule\Required;

final class Car
{
    #[Required]
    #[HasLength(min: 3, skipOnEmpty: true)]
    public string $name = '';

    #[Required]
    #[SymfonyRule(
        new CssColor(CssColor::RGB), // Symfony constraint
        skipOnEmpty: true,
    )]
    public string $cssColor = '#1123';

    #[SymfonyRule([
        new Positive(), // Symfony constraint
        new NotEqualTo(13), // Symfony constraint
    ])]
    public int $number = 13;
}

SymfonyRule rule parameters

$constraint — Single or array of Symfony validation constraints. Required.

$skipOnEmpty — Whether skip rule on empty value or not, and which value consider as empty. Defaults to null.

$skipOnError — A boolean value where true means to skip rule when the previous one errored and false — do not skip. Defaults to false.

$when — The closure that allow to apply rule under certain conditions only. Defaults to null.

SymfonyRuleHandler parameters

$symfonyValidator — Symfony validator instance. Defaults to validator created by Symfony\Component\Validator\Validation::createValidator().

Testing

Unit testing

The package is tested with PHPUnit. To run tests:

./vendor/bin/phpunit

Mutation testing

The package tests are checked with Infection mutation framework with Infection Static Analysis Plugin. To run it:

./vendor/bin/roave-infection-static-analysis-plugin

Static analysis

The code is statically analyzed with Psalm. To run static analysis:

./vendor/bin/psalm

License

The Yii Validator Symfony Rule is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2022-12-21