dealnews/constraints

Type constraint checking library

v2.2.1 2024-01-19 22:25 UTC

This package is auto-updated.

Last update: 2024-11-20 00:31:31 UTC


README

A library for testing primitive and abstract data types in PHP with type juggling.

Supported Primitive Types

  • Integer
  • String
  • Array
  • Double (aka float)
  • Boolean
  • Any defined PHP class

Supported Abstract Types

  • Bytes
  • US Currency
  • Date
  • DateTime
  • Length
  • Range
  • Time
  • URL
  • URL Path
  • Year

Extendable

The base Constraint class can be extended to add new abstract types.

Example

// A very simple example
$constraint = \DealNews\Constraints\Constraint::init();
$value = "1";
try {
    $value = $constraint->check($value, ["type" => "integer"]);
    // $value will now be integer 1
} catch (\DealNews\Constraints\ConstraintException $e) {
    echo $e->getMessage();
}