Skip to content
Pieter Hordijk edited this page Jan 1, 2019 · 1 revision

TOC

ArrayType

Validates the input (mixed) to be an array.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Type\ArrayType;

(new ArrayType())->validate(['foo', 'bar']);

Failure reasons

  • Type.ArrayType when the validated value is not an array

BooleanType

Validates the input (mixed) to be a bool.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Type\BooleanType;

(new BooleanType())->validate(true);

Failure reasons

  • Type.BooleanType when the validated value is not a boolean

CallableType

Validates the input (mixed) to be a callable.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Type\CallableType;

(new CallableType())->validate(function() {});

Failure reasons

  • Type.CallableType when the validated value is not a callable

FloatType

Validates the input (mixed) to be a float.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Type\FloatType;

(new FloatType())->validate('12.4');

Failure reasons

  • Type.FloatType when the validated value is not a float

InstanceOfType

Validates the input (mixed) to be an instance of string type.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Type\InstanceOfType;

(new InstanceOfType(\DateTimeInterface::class))->validate(\new DateTimeImmutable());

Failure reasons

  • Type.InstanceOfType when the validated value is not an instance of string type

IntegerType

Validates the input (mixed) to be an int.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Type\IntegerType;

(new IntegerType())->validate(10);

Failure reasons

  • Type.IntegerType when the validated value is not an int

IterableType

Validates the input (mixed) to be an iterable.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Type\IterableType;

(new IterableType())->validate(['foo']);

Failure reasons

  • Type.IterableType when the validated value is not an iterable

NullType

Validates the input (mixed) to be NULL.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Type\NullType;

(new NullType())->validate(null);

Failure reasons

  • Type.NullType when the validated value is not NULL

ObjectType

Validates the input (mixed) to be an object.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Type\ObjectType;

(new ObjectType())->validate(new \DateTimeImmutable());

Failure reasons

  • Type.ObjectType when the validated value is not an object

ResourceType

Validates the input (mixed) to be a resource.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Type\ResourceType;

(new ResourceType())->validate(fopen('/path/to/file', 'r'));

Failure reasons

  • Type.ResourceType when the validated value is not a resource

StringType

Validates the input (mixed) to be a string.

Version information

Available since: 1.0.0

Usage

<?php declare(strict_types);

use HarmonyIO\Validation\Rule\Type\StringType;

(new StringType())->validate('A string');

Failure reasons

  • Type.StringType when the validated value is not a string