dealnews / constraints
Type constraint checking library
Installs: 8 073
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 8
Forks: 1
Open Issues: 0
Requires
- php: ^8.0
- ext-mbstring: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.38
- php-parallel-lint/php-parallel-lint: ^1.3
- phpunit/phpunit: ^9.6
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(); }