Download the PHP package harmonyio/validation without Composer
On this page you can find all versions of the php package harmonyio/validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package validation
Validation
Async validation library
Requirements
- PHP 7.3
- ext-ctype
- ext-dom
- ext-fileinfo
- ext-filter
- ext-gd
- ext-hash
- ext-json
- ext-libxml
- ext-mbstring
- Redis
In addition for non-blocking context one of the following event libraries should be installed:
Installation
Usage
This library is based on the amphp concurrency framework.
Basic usage
Validating a value against a single rule:
This will result in the following Result
object:
Stacking validation rules
Validation rules can be stacked on top of each other when you want to apply multiple rules to the same value:
This will result in the following Result
object:
Validation rules
There is already an elaborate list of validation rules implemented. For an overview of all supported rules please see the documentation in the wiki.
All validation rules adhere to the same interface:
This will ensure any value can always be passed in to be validated and it will always result in a promise which resolved to a Result
object.
If you are missing a validation rule feel free to open an issue.
Combinators
Combinators are a way to combine multiple validation rules into a single result.
This can be used to build more complex validation rules based on existing rules.
Results and errors
All validation always result in a HarmonyIO\Validation\Result\Result
object.
To check whether a value is valid after validating we can simply call the HarmonyIO\Validation\Result\Result::isValid()
method which returns a simple boolean.
If the validation fails the validation errors can be accessed using one of two methods on the Result
object:
HarmonyIO\Validation\Result\Result::getFirstError()
- Returns eithernull
when there were no errors or aHarmonyIO\Validation\Result\Error
object otherwiseHarmonyIO\Validation\Result\Result::getErrors()
- Returns an array withHarmonyIO\Validation\Result\Error
objects
Errors
When validation results in an invalid result at least one Error
object will be added to the Result
object.
An error object always has an error message (which can be used for translation for rendering in your project) and zero or more parameters.
Parameters are used when failed validation rules are based on dynamic values. I.e. when the validation rule for minimum length of text fails it will result in the following Error
object:
Traditional / blocking usage
Although this project is based on async programming it is also possible to use it in a more traditional blocking way using the wait()
helper function:
Rules
An overview of all implemented rules (including usage and version information) is documented in the wiki.
All versions of validation with dependencies
ext-ctype Version *
ext-dom Version *
ext-fileinfo Version *
ext-filter Version *
ext-gd Version *
ext-hash Version *
ext-json Version *
ext-libxml Version *
ext-mbstring Version *
amphp/amp Version ^2.1.1
amphp/artax Version ^3.0.14
amphp/dns Version ^0.9.13
amphp/file Version ^0.3.3
amphp/parallel-functions Version ^0.1.3
amphp/process Version ^1.0.2
amphp/uri Version ^0.1.3
egulias/email-validator Version ^2.1.1
harmonyio/cache Version ^1.0.0-rc1
harmonyio/http-client Version ^1.0.0-rc1
myclabs/php-enum Version ^1.6.4
react/promise Version ^2.7.0
wikimedia/ip-set Version ^2.0.0