Download the PHP package weew/validator without Composer
On this page you can find all versions of the php package weew/validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package validator
PHP Validator
Table of contents
- Installation
- Available constraints
- Additional constraint packs
- Constraints
- Constraint groups
- Validator
- Validation result and validation errors
- Composing a custom validator
- Creating a custom validator class
- Custom constraints
- Wildcard validation
- Property accessors
- Array accessor
- Object accessor
- Getter accessor
- Contributing constraints
Installation
composer require weew/validator
Available constraints
- Accepted
- Allowed
- AllowedSubset
- Alpha
- AlphaNumeric
- Array
- Boolean
- DomainName
- Equals
- Float
- Forbidden
- ForbiddenSubset
- Integer
- IP
- IPv4
- IPv6
- Length
- MaxAddress
- Max
- MaxLength
- Min
- MinLength
- MinMax
- MinMaxLength
- NotEmpty
- NotNull
- Nullable
- Null
- Numeric
- Regex
- Scalar
- String
- Url
Additional constraint packs
There are additional constraints that you may load trough composer.
Constraints
Constraints are small pieces of validation logic. A constraint can be used on its own, without the validator.
Constraint groups
Constraint groups allows you to configure multiple constraints for a single value.
Constraint groups can be used to validate data without the validator. The method returns a object.
Validator
The easiest way to use the validator is by creating a new instance and adding constraints inline. Validator will return a object.
Validation result and validation errors
Validation result is used to group occurring validation errors. Validation errors hold information about the validated properties, their values and the applied constraints.
Composing a custom validator
You can compose a validator with predefined constraints that will be applied on each validation.
Creating a custom validator class
Configuring validators inline is not always the best solution. Sometimes you might want to create dedicated validator classes. With this library this is very easy to achieve.
Custom constraints
Creating a new constraint is a fairly easy task. All you have to do is to implement the interface. This is an example on how to create a simple constraint that makes sure that a number is within the given range.
Wildcard validation
Imagine you have a similar structure that you want to validate.
In order to validate the name
property of every single element inside the items
array, you would have to iterate over the items manually. You could also use a wildcard to target all the values. To wildcard array values, you can use this special character *
.
In the example above, result will hold an error with subject items.1.name
.
Array keys can also be validated using wildcards. You'll have to use a different wildcard character #
. Be aware that the #
wildcard character should always be the last path segment. This is wrong foo.#.bar
, this is ok foo.bar.#
.
Result will contain an error with subject #items.1
. As you see, there is a #
prefix in front of subjects for wildcard keys. This way you can differentiate between subjects for values and subjects for keys.
Property accessors
Validator comes with support for multiple data types.
Array accessor
This accessor adds support for array based data sets.
Object accessor
This accessor adds support for object based data sets.
Getter accessor
This accessor adds support for objects that only allow to access data over getter methods.
All versions of validator with dependencies
weew/contracts Version ^1.1
weew/helpers-array Version ^1.0