Skip to content

peakphp/array-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Peak/ArrayValidation

version Total Downloads License

Installation

 composer require peak/array-validation

Usage

General validation (stateless)

$validator = new Validator();

if ($validator->expectExactlyKeys($array, ['key1', 'key2', 'key3']) === true) {
    // ...
}

Advanced validation with fluent interface.

$validation = new StrictValidation($array);

// will throw an exception if any of tests below fail
$validation
    ->expectOnlyKeys(['id', 'title', 'description', 'isPrivate', 'tags'])
    ->expectAtLeastKeys(['id', 'title', 'description'])
    ->expectKeyToBeInteger('id')
    ->expectKeysToBeString(['title', 'description'])
    ->expectKeyToBeBoolean('isPrivate')
    ->expectKeyToBeArray('tags');

// if we reach this point, it means the array is 
// valid according to the validation rules above.

About

Validation utilities for array structure

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages