mf/type-validator

TypeValidator for asserting types of values

4.1.0 2022-01-14 13:44 UTC

This package is auto-updated.

Last update: 2024-11-14 19:50:38 UTC


README

Latest Stable Version Tests and linting Coverage Status Total Downloads License

TypeValidator for asserting types of values

Table of Contents

Requirements

  • PHP 8.0

Installation:

composer require mf/type-validator

Usage

$validator = new TypeValidator(
    TypeValidator::TYPE_STRING,
    TypeValidator::TYPE_INT,
    [TypeValidator::TYPE_STRING],
    [TypeValidator::INT]
);

$validator->assertKeyType('string - value');
$validator->assertValueType(1);

$validator->assertValueType('invalid value type');  // throws InvalidArgumentException

With Custom Exception

$validator = new TypeValidator(
    TypeValidator::TYPE_STRING,
    TypeValidator::TYPE_INT,
    [TypeValidator::TYPE_STRING],
    [TypeValidator::INT],
    App\MyCustomException::class
);

$validator->assertKeyType('string - value');
$validator->assertValueType(1);

$validator->assertValueType('invalid value type');  // throws App\MyCustomException