markwilson/symfony2-validator-fields-intersect-not-empty

This package is abandoned and no longer maintained. No replacement package was suggested.

Constraint to check at least one of the keys exist in an array

2.2.0 2013-12-11 14:39 UTC

This package is not auto-updated.

Last update: 2021-01-23 09:24:39 UTC


README

Note: currently only works for validator component 2.2.x

Constraint to check if an array contains at least one of the provided keys.

Install

Add markwilson/symfony2-validator-fields-intersect-not-empty to composer.json requires.

Usage

FieldsIntersectNotEmpty requires a fields option which takes an array of keys to search in the validating value.

e.g.

use MarkWilson\Validator\Constraints\FieldsIntersectNotEmpty;
use Symfony\Component\Validator\Validation;

$constraint = new FieldsIntersectNotEmpty(array('one', 'of', 'these', 'must', 'exist');

$validator = Validation::createValidator();

$value = array('nothing' => true, 'matches' => true);
$validator->validateValue($value, $constraint); // invalid

$value = array('exist' => true, 'matches' => true);
$validator->validateValue($value, $constraint); // valid