Skip to content

Combinator

Pieter Hordijk edited this page Dec 30, 2018 · 1 revision

TOC

All

Used to combine multiple rules. Validation only succeeds when all rules succeed.
Validation rules are supplied in the constructor of the All rule. All supplied validators must implement \HarmonyIO\Validation\Rule\Rule.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Combinator\All;
use HarmonyIO\Validation\Rule\Text\Ascii;
use HarmonyIO\Validation\Rule\Text\MinimumLength;
use HarmonyIO\Validation\Rule\Text\NoControlCharacters;

(new All(
    new Ascii(),
    new MinimumLength(10),
    new NoControlCharacters(),
))->validate('Lorem ipsum dolor sit amet');

Failure reasons

List of failures of the validation rules used.

Any

Used to combine multiple rules. Validation succeeds when a single rule succeeds.
Validation rules are supplied in the constructor of the Any rule. All supplied validators must implement \HarmonyIO\Validation\Rule\Rule.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Combinator\Any;
use HarmonyIO\Validation\Rule\Text\Ascii;
use HarmonyIO\Validation\Rule\Text\MinimumLength;
use HarmonyIO\Validation\Rule\Text\NoControlCharacters;

(new Any(
    new Ascii(),
    new MinimumLength(10),
    new NoControlCharacters(),
))->validate('Lorem ipsum dolor sit amet');

Failure reasons

List of failures of the validation rules used when none of the validators succeed.

AtLeast

Used to combine multiple rules. Validation succeeds when at least the minimum number of successful rules (int) are hit.
Validation rules are supplied in the constructor of the AtLeast rule. All supplied validators must implement \HarmonyIO\Validation\Rule\Rule.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Combinator\AtLeast;
use HarmonyIO\Validation\Rule\Text\Ascii;
use HarmonyIO\Validation\Rule\Text\MinimumLength;
use HarmonyIO\Validation\Rule\Text\NoControlCharacters;

(new AtLeast(
    2,
    new Ascii(),
    new MinimumLength(10),
    new NoControlCharacters(),
))->validate('Lorem ipsum dolor sit amet');

Failure reasons

List of failures of the validation rules used when none of the validators succeed.

Negate

Used to negate the result of a validator. Validation succeeds when the validator fails.
The validation rule to negate is supplied in the constructor of the Negate rule. The supplied validator must implement \HarmonyIO\Validation\Rule\Rule.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Combinator\Negate;
use HarmonyIO\Validation\Rule\Text\Ascii;

(new Negate(new Ascii()))->validate('Lorem ipsum dolor sit amet');

Failure reasons

  • Combinator.Negate when the passed in validator succeeds.

Clone this wiki locally