PHPackages                             bcastellano/symfony-validator-conditional - 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. bcastellano/symfony-validator-conditional

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

bcastellano/symfony-validator-conditional
=========================================

Symfony validator for conditional validations based on object properties

v1.0.1(9y ago)237.5k↓50%1MITPHPPHP &gt;=5.3.3

Since May 16Pushed 9y ago1 watchersCompare

[ Source](https://github.com/bcastellano/symfony-validator-conditional)[ Packagist](https://packagist.org/packages/bcastellano/symfony-validator-conditional)[ RSS](/packages/bcastellano-symfony-validator-conditional/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/a33bec965c189b7fda495706a66271910b47f1ede957a6b2c1cf6e6893d71651/68747470733a2f2f7472617669732d63692e6f72672f6263617374656c6c616e6f2f73796d666f6e792d76616c696461746f722d636f6e646974696f6e616c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bcastellano/symfony-validator-conditional)[![Coverage Status](https://camo.githubusercontent.com/5e8cf139397b6364a42a447f670c8ec21c8a899a2277b8c1f72c1c9cbeff56cc/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6263617374656c6c616e6f2f73796d666f6e792d76616c696461746f722d636f6e646974696f6e616c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/bcastellano/symfony-validator-conditional?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/055aa53a2911a299b9e450ce382f6dd4ae02f33943a00913856227805808743f/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f66353434656236632d396331632d343732382d383735382d6536643364303034616639652f6d696e692e706e67)](https://insight.sensiolabs.com/projects/f544eb6c-9c1c-4728-8758-e6d3d004af9e)[![License](https://camo.githubusercontent.com/e498eead712d82d9ee1af0a4850acd2e46ea48c48fb9ce5a3d2ab64f28f95b34/687474703a2f2f696d672e736869656c64732e696f2f3a6c6963656e73652d6d69742d626c75652e737667)](http://doge.mit-license.org)

Symfony Conditional validator
=============================

[](#symfony-conditional-validator)

Symfony validator for conditional validations based on object properties

Install
-------

[](#install)

The recommended way to install is through composer:

```
$ composer require bcastellano/symfony-validator-conditional
```

or adding to require section in `composer.json`

Usage
-----

[](#usage)

You can use PHP, Annotations, YAML or XML.

### Configuration example with PHP

[](#configuration-example-with-php)

```
// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;

use Bcastellano\Symfony\Validator\Constraints\Conditional;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;

class User
{
    public static function loadValidatorMetadata(ClassMetadata $metadata)
    {
        // property validator usage
        $metadata->addPropertyConstraint('name', new Conditional(array(
            'constraints' => array(
                new Assert\NotBlank(),
            ),
            'condition' => function($value){

                // add login here... $value is object of this property and can be use to check context

                return $boolean;
            }
        )));

        // class validator usage
        $metadata->addConstraint(new Conditional(array(
            'constraints' => array(
                new Assert\Callback('validate'),
            ),
            'condition' => function($value){

                // add login here... $value is object validating and can be use to check context

                return $boolean;
            }
        )));
    }
}
```

### Configuration example with annotations

[](#configuration-example-with-annotations)

```
// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;

use Bcasellano\Symfony\Validator\Constraints\Conditional;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Mapping\ClassMetadata;

/**
 * Class validator
 *
 * @Conditional(
 *     constraints = {
 *         @Assert\Callback({"AppBundle\Entity\User","validate"})
 *     },
 *     condition = "AppBundle\Entity\User::shouldValidateName"
 * )
 */
class User
{
    /**
     * Property validator
     *
     * @Conditional(
     *     constraints = {
     *         @Assert\NotBlank()
     *     },
     *     condition = "AppBundle\Entity\User::shouldValidateName"
     * )
     */
    protected $name;

    public static function shouldValidateName($object)
    {
        // add login here... $value is object validating and can be use to check context

        return $boolean;
    }

    public static function validate($object, ExecutionContextInterface $context, $payload)
    {
        // ...
    }
}
```

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community8

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 ~173 days

Total

2

Last Release

3472d ago

### Community

Maintainers

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

---

Top Contributors

[![bcastellano](https://avatars.githubusercontent.com/u/393491?v=4)](https://github.com/bcastellano "bcastellano (10 commits)")

---

Tags

phpsymfonyvalidatorSymfony2symfony3condition

### Embed Badge

![Health badge](/badges/bcastellano-symfony-validator-conditional/health.svg)

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

###  Alternatives

[rollerworks/password-strength-validator

Password-strength validator for Symfony

1455.7M5](/packages/rollerworks-password-strength-validator)

PHPackages © 2026

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