Download the PHP package elie29/validator without Composer
On this page you can find all versions of the php package elie29/validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package validator
Validator Project
Introduction
A library for validating a context (POST, GET etc...) by running given rules.
Installation
Run the command below to install via Composer:
Getting Started
Validator
requires one or several rules (constraints) in order to validate a given context.
A basic example with \$_POST
Available rules
- All Rules accept
required
,trim
andmessages
options.required
is false by default whiletrim
is true. - ArrayRule accepts
min
andmax
options. Empty value is cast to empty array []. - BicRule
- BooleanRule accepts
cast
option. - CallableRule accepts
callable
function. - ChoicesRule accepts
list
option. - CollectionRule accepts
list
andjson
options. - CompareRule accepts
sign
andexpected
options.sign
is CompareRule::EQ by default,expected
is null by default. - DateRule accepts
format
andseparator
options. - EmailRule
- IpRule accepts
flag
option. - JsonRule accepts
decode
option - MatchRule requires
pattern
option. - MultipleAndRule requires
rules
option. - MultipleOrRule requires
rules
option. - NumericRule accepts
min
,max
andcast
options. - RangeRule accepts
range
option. - StringRule accepts
min
andmax
options. - TimeRule
- Your own rule
How to add a new rule
You need to implement RuleInterface or to extend AbstractRule
Validated Context
Once validate is called, we can use validatedContext method in order to retrieve all validated values from the original context.
By default, all keys set in the rules array will be found in the validatedContext array. However, if we don't want to append non existing keys, we should call appendExistingItemsOnly(true) before validation.
Assertion Integration
Instead of using assertion key by key, you can validate the whole context and than use Assertion or Assert as follow:
Partial Validation
Sometimes we need to validate the context partially, whenever we have a Json item or keys that depend on each others.
The following is an example when a context - eg. \$_POST - should contains a Json user data:
Partial Validation with a multidimensional array
Usually with JsonRule, we could expect a multidimensional array. In this case, the validation process will be similar to Partial Validation without merging data:
A new CollectionRule has been added in order to validate a collection data (array or json) as follow:
Development Prerequisites
Text file encoding
- UTF-8
Code style formatter
- Zend Framework coding standard
Composer commands
clean
: Cleans all generated filestest
: Launches unit testtest-coverage
: Launches unit test with clover.xml file generationcs-check
: For code sniffer checkcs-fix
: For code sniffer fixphpstan
: Launches PHP Static Analysis Toolcheck
: Launchesclean
,cs-check
,test
andphpstan
All versions of validator with dependencies
ext-json Version *