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,trimandmessagesoptions.requiredis false by default whiletrimis true. - ArrayRule accepts
minandmaxoptions. Empty value is cast to empty array []. - BicRule
- BooleanRule accepts
castoption. - CallableRule accepts
callablefunction. - ChoicesRule accepts
listoption. - CollectionRule accepts
listandjsonoptions. - CompareRule accepts
signandexpectedoptions.signis CompareRule::EQ by default,expectedis null by default. - DateRule accepts
formatandseparatoroptions. - EmailRule
- IpRule accepts
flagoption. - JsonRule accepts
decodeoption - MatchRule requires
patternoption. - MultipleAndRule requires
rulesoption. - MultipleOrRule requires
rulesoption. - NumericRule accepts
min,maxandcastoptions. - RangeRule accepts
rangeoption. - StringRule accepts
minandmaxoptions. - 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,testandphpstan
All versions of validator with dependencies
ext-json Version *