Download the PHP package fesor/symfony-validator-extra without Composer
On this page you can find all versions of the php package fesor/symfony-validator-extra. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fesor/symfony-validator-extra
More information about fesor/symfony-validator-extra
Files in fesor/symfony-validator-extra
Package symfony-validator-extra
Short Description Symfony Validator Extras for more simple handling of complex cases
License MIT
Informations about the package symfony-validator-extra
Symfony Validator Extras
In order to simplify request validation and reduce amount of boilerplate, this package provides you set of additional constraints.
Json and FixedJson constraints
If you are dealing with json requests, you probably hate Collection
validator. As a replacement this library provides you two additional constraints: JsonValidator
and FixedJsonValidator
.
The difference between JsonValidator
and FixedJsonValidator
, which is both extends from CollectionValidator
, is that
they use different value for option allowExtraFields
. FixedJson
doesn't allow extra fields, but Json
- just ignores that.
Shortcuts
This validator provides you some shortcuts for common validators:
this is equivalent of
List of available shortcuts:
ShortCut | Constraint Used |
---|---|
date |
new Date() |
datetime |
new DateTime() |
time |
new Time() |
email |
new Email() |
url |
new Url() |
file |
new File() |
image |
new Image() |
null |
new IsNull() |
*any strhing* |
new Type('*any strhing*') |
Null Safety
By default all constraint (except null
) shortcuts expands with NotNull
constraint. If null
is acceptable value
for you, you can just add question mark at the beginning of shortcut. So this rules will be equivalent:
The syntax is taken from PHP 7.1
Optional fields
If your json request has optional keys, then you probably will write something like this:
With JsonValidator
the same rule can be written as:
Please note that question mark (?
) will be skipped if you manually provide info about is this field is required or not.
So using this rule:
validator will expect foo?
containing not null value. And property bar?
considered as optional since it has question
mark in it's end (?
).