PHPackages                             vjik/yii-validator-symfony-rule - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. vjik/yii-validator-symfony-rule

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

vjik/yii-validator-symfony-rule
===============================

Symfony validation constraints adapter for Yii Validator

1.0.0(3y ago)2912BSD-3-ClausePHPPHP ^8.0

Since Feb 22Pushed 3y ago1 watchersCompare

[ Source](https://github.com/vjik/yii-validator-symfony-rule)[ Packagist](https://packagist.org/packages/vjik/yii-validator-symfony-rule)[ RSS](/packages/vjik-yii-validator-symfony-rule/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

 [![](https://camo.githubusercontent.com/8317c17418b39410a660f5149071d26c5023c0d5fb2b7ebb771324812f666d73/68747470733a2f2f796969736f66742e6769746875622e696f2f646f63732f696d616765732f7969695f6c6f676f2e737667)](https://camo.githubusercontent.com/8317c17418b39410a660f5149071d26c5023c0d5fb2b7ebb771324812f666d73/68747470733a2f2f796969736f66742e6769746875622e696f2f646f63732f696d616765732f7969695f6c6f676f2e737667) [![](symfony-logo.svg)](symfony-logo.svg)

Yii Validator Symfony Rule
==========================

[](#yii-validator-symfony-rule)

[![Latest Stable Version](https://camo.githubusercontent.com/90887104d084c285841bbd3b2b39613af6add54fa5b66ac00a32b3f1b6cb1433/68747470733a2f2f706f7365722e707567782e6f72672f766a696b2f7969692d76616c696461746f722d73796d666f6e792d72756c652f762f737461626c652e706e67)](https://packagist.org/packages/vjik/yii-validator-symfony-rule)[![Total Downloads](https://camo.githubusercontent.com/e069e6c28c9d65d0e21afd06157a177d3dc7240a3e84cd7c0dbe8b20f3c0de77/68747470733a2f2f706f7365722e707567782e6f72672f766a696b2f7969692d76616c696461746f722d73796d666f6e792d72756c652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/vjik/yii-validator-symfony-rule)[![Build status](https://github.com/vjik/yii-validator-symfony-rule/workflows/build/badge.svg)](https://github.com/vjik/yii-validator-symfony-rule/actions?query=workflow%3Abuild)[![Mutation testing badge](https://camo.githubusercontent.com/8234a34b14bfa808ad39dbd6c4b857d918b9b42118e9c81adf9bfb0839b2605b/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d253246766a696b2532467969692d76616c696461746f722d73796d666f6e792d72756c652532466d6173746572)](https://dashboard.stryker-mutator.io/reports/github.com/vjik/yii-validator-symfony-rule/master)[![type-coverage](https://camo.githubusercontent.com/b2dd91a14c7074c201e99218adbd0c7f69a36fc648d2779eac34ea892347887a/68747470733a2f2f73686570686572642e6465762f6769746875622f766a696b2f7969692d76616c696461746f722d73796d666f6e792d72756c652f636f7665726167652e737667)](https://shepherd.dev/github/vjik/yii-validator-symfony-rule)[![static analysis](https://github.com/vjik/yii-validator-symfony-rule/workflows/static%20analysis/badge.svg)](https://github.com/vjik/yii-validator-symfony-rule/actions?query=workflow%3A%22static+analysis%22)[![psalm-level](https://camo.githubusercontent.com/06dde206c614ef7eb0ae2e04fe7c96db427473599d46bb39dbc813a730bf6c3b/68747470733a2f2f73686570686572642e6465762f6769746875622f766a696b2f7969692d76616c696461746f722d73796d666f6e792d72756c652f6c6576656c2e737667)](https://shepherd.dev/github/vjik/yii-validator-symfony-rule)

The package provides validator rule `SymfonyRule` that allow use Symfony validation constraints in [Yii Validator](https://github.com/yiisoft/validator).

Requirements
------------

[](#requirements)

- PHP 8.0 or higher.

Installation
------------

[](#installation)

The package could be installed with [composer](https://getcomposer.org/download/):

```
composer require vjik/yii-validator-symfony-rule
```

General usage
-------------

[](#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
-----------------------------

[](#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
-------------------------------

[](#symfonyrulehandler-parameters)

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

Testing
-------

[](#testing)

### Unit testing

[](#unit-testing)

The package is tested with [PHPUnit](https://phpunit.de/). To run tests:

```
./vendor/bin/phpunit
```

### Mutation testing

[](#mutation-testing)

The package tests are checked with [Infection](https://infection.github.io/) mutation framework with [Infection Static Analysis Plugin](https://github.com/Roave/infection-static-analysis-plugin). To run it:

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

### Static analysis

[](#static-analysis)

The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:

```
./vendor/bin/psalm
```

License
-------

[](#license)

The Yii Validator Symfony Rule is free software. It is released under the terms of the BSD License. Please see [`LICENSE`](./LICENSE.md) for more information.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1229d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/53e5ee1dedd50f71e4aeeac2929f786cdfb400359d4776e6cd806388d0d5df2c?d=identicon)[vjik](/maintainers/vjik)

---

Top Contributors

[![vjik](https://avatars.githubusercontent.com/u/525501?v=4)](https://github.com/vjik "vjik (7 commits)")

---

Tags

constraintssymfonyvalidationvalidatoryii3symfonyvalidatorvalidationyiiconstraints

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/vjik-yii-validator-symfony-rule/health.svg)

```
[![Health](https://phpackages.com/badges/vjik-yii-validator-symfony-rule/health.svg)](https://phpackages.com/packages/vjik-yii-validator-symfony-rule)
```

###  Alternatives

[barbieswimcrew/zip-code-validator

Constraint class for international zipcode validation

772.5M](/packages/barbieswimcrew-zip-code-validator)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[api-platform/validator

API Platform validator component

274.6M27](/packages/api-platform-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
