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

TOC

Exact

Validates the input (instance of a \DateTimeInterface) to be an exact match of the age (int).

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Age\Exact;

(new Exact(18))->validate(new \DateTimeImmutable('2018-12-13'));

Failure reasons

  • Type.InstanceOfType when the validated value is not an instance of \DateTimeInterface
  • Age.Minimum when the validated value is less than the target value as defined in the constructor
  • Age.Maximum when the validated value is more than the target value as defined in the constructor

Maximum

Validates the input (instance of a \DateTimeInterface) to be younger or exactly the maximum age (int).

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Age\Maximum;

(new Maximum(18))->validate(new \DateTimeImmutable('2018-12-13'));

Failure reasons

  • Type.InstanceOfType when the validated value is not an instance of \DateTimeInterface
  • Age.Maximum when the validated value is more than the target value as defined in the constructor

Minimum

Validates the input (instance of a \DateTimeInterface) to be older or exactly the minimum age (int).

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Age\Minimum;

(new Minimum(18))->validate(new \DateTimeImmutable('2018-12-13'));

Failure reasons

  • Type.InstanceOfType when the validated value is not an instance of \DateTimeInterface
  • Age.Minimum when the validated value is less than the target value as defined in the constructor

Range

Validates the input (instance of a \DateTimeInterface) to be within range of minimum age (int) and maximum age (int) inclusive.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Age\Range;

(new Range(18, 65))->validate(new \DateTimeImmutable('2018-12-13'));

Failure reasons

  • Type.InstanceOfType when the validated value is not an instance of \DateTimeInterface
  • Age.Minimum when the validated value is less than the minimum age as defined in the constructor
  • Age.Maximum when the validated value is more than the maximum age as defined in the constructor
Clone this wiki locally