PHPackages                             petrabarus/yii2-switchcasevalidator - 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. petrabarus/yii2-switchcasevalidator

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

petrabarus/yii2-switchcasevalidator
===================================

Validator that will run on switch-case-like conditional

1.0.1(10y ago)114.3kMITPHPPHP &gt;=5.5.0

Since Jun 17Pushed 10y ago1 watchersCompare

[ Source](https://github.com/petrabarus/yii2-switchcasevalidator)[ Packagist](https://packagist.org/packages/petrabarus/yii2-switchcasevalidator)[ RSS](/packages/petrabarus-yii2-switchcasevalidator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Yii2 Switch Case Validator
==========================

[](#yii2-switch-case-validator)

Validator that will run on switch-case-like conditional

[![Latest Stable Version](https://camo.githubusercontent.com/50e297cd086c92edaa2c4d74d943c798c07e40e57bc588d127dc720021295b0a/68747470733a2f2f706f7365722e707567782e6f72672f706574726162617275732f796969322d7377697463686361736576616c696461746f722f762f737461626c652e737667)](https://packagist.org/packages/petrabarus/yii2-switchcasevalidator)[![Total Downloads](https://camo.githubusercontent.com/eedbac803ecb37900ac3a116f737a7d3b60cb93539ade39bac37d7a462b351ff/68747470733a2f2f706f7365722e707567782e6f72672f706574726162617275732f796969322d7377697463686361736576616c696461746f722f646f776e6c6f6164732e737667)](https://packagist.org/packages/petrabarus/yii2-switchcasevalidator)[![Latest Unstable Version](https://camo.githubusercontent.com/34a8d02d382c181c281b6d1d0a45b6f15de2bfd62ec00ede785f8a1944667cdf/68747470733a2f2f706f7365722e707567782e6f72672f706574726162617275732f796969322d7377697463686361736576616c696461746f722f762f756e737461626c652e737667)](https://packagist.org/packages/petrabarus/yii2-switchcasevalidator)[![Build Status](https://camo.githubusercontent.com/59b6b15473d66fd1496b682ea10852a2cc4412c5376f6c300190eb098ae85fa5/68747470733a2f2f7472617669732d63692e6f72672f706574726162617275732f796969322d7377697463686361736576616c696461746f722e7376673f6272616e63683d6164642d7472617669732d6369)](https://travis-ci.org/petrabarus/yii2-switchcasevalidator)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist petrabarus/yii2-switchcasevalidator "*"

```

or add

```
"petrabarus/yii2-switchcasevalidator": "*"

```

to the require section of your `composer.json` file.

Requirement
-----------

[](#requirement)

This package require

- Latest Yii2
- PHP 5.4 or later

Usage
-----

[](#usage)

Add something like this in the model `rules()`.

```
    //Assuming the model has attribute case, field1, and field2.
    //Each rule group will be validated when the case attribute match the cases.
    public function rules() {
        ['case', PetraBarus\Yii2\SwitchCaseValidator\Validator::class,
            //For PHP 5.4, you can use PetraBarus\Yii2\SwitchCaseValidator\Validator::className() or
            // string 'PetraBarus\Yii2\SwitchCaseValidator\Validator'
            'cases' => [
                1 => [
                    ['field1', 'required'],
                ],
                2 => [
                    ['field1', 'compare', 'compareValue' => 'Test']
                ],
                3 => [
                    ['field1', 'compare', 'compareValue' => 'Value 1'],
                    ['field2', 'email']
                ]
            ],
            //This will be executed if no cases matches.
            'default' => [
                ['field1', 'compare', 'compareValue' => 'Value 2'],
                ['field1', 'compare', 'compareValue' => 'Value 4'],
            ]
        ]
    }
```

Or see the test files.

Test
----

[](#test)

To run test, execute

```
  $ phpunit

```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Every ~105 days

Total

2

Last Release

3884d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c1261f29f95a5ca228a04c8415431baf0fb6c397ec83e93e3454fb0b55718c5e?d=identicon)[petrabarus](/maintainers/petrabarus)

---

Top Contributors

[![petrabarus](https://avatars.githubusercontent.com/u/523289?v=4)](https://github.com/petrabarus "petrabarus (8 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/petrabarus-yii2-switchcasevalidator/health.svg)

```
[![Health](https://phpackages.com/badges/petrabarus-yii2-switchcasevalidator/health.svg)](https://phpackages.com/packages/petrabarus-yii2-switchcasevalidator)
```

###  Alternatives

[borales/yii2-phone-input

Yii2 International telephone numbers - Asset Bundle, Behavior, Validator, Widget

1341.6M6](/packages/borales-yii2-phone-input)[codeonyii/yii2-at-least-validator

Validates at least one (or more) attributes.

28253.5k1](/packages/codeonyii-yii2-at-least-validator)[arogachev/yii2-many-to-many

Many-to-many ActiveRecord relation for Yii 2 framework

3541.2k4](/packages/arogachev-yii2-many-to-many)[yiibr/yii2-br-validator

Provide validations and features for brazilian localization

14103.2k4](/packages/yiibr-yii2-br-validator)[yii2mod/yii2-validators

Collection of useful validators for Yii Framework 2.0

1816.8k](/packages/yii2mod-yii2-validators)

PHPackages © 2026

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