However, it is actually an instead unusual use-case that a verification regulation requires to become defined merely in the operator.

Using Validators & & The ValidatorResolver

A validator is actually a PHP lesson being accountable for check my email validity of a certain item or even basic kind.

All validators apply \ Neos \ Flow \ Validation \ Validator \ ValidatorInterface , as well as the API of every validator is displayed in the adhering to code instance:

// NOTE: you must regularly utilize the ValidatorResolver to generate brand-new.
// validators, as it is demonstrated in the following segment.
$ validator =  brand-new  \ Neos \ Circulation \ Verification \ Validator \ StringLengthValidator  (range (.
' minimal'  =>>   10 ,.
' optimum'  =>>   twenty 
));.

// $result is of style Neos \ Inaccuracy \ Information \ Outcome 
$ lead  =  $ validator  ->>  validate (' myExampleString'  );.
$ lead  ->>  hasErrors (); // is actually FALSE, as the string is longer than 10 characters. 

$ lead  =  $ validator  ->>  legitimize (' brief'  );.
$ lead  ->>  hasErrors (); // holds true, as the strand is actually very brief. 
$ lead  ->>  getFirstError () ->>  getMessage (); // includes the human-readable error message 

On the above example, it may be observed that validators can be re-used for different input. On top of that, a validator does certainly not merely come back ACCURATE or even UNTRUSTWORTHY, yet as an alternative comes back a Result item whichyou can talk to whether any type of mistakes happened. Desire find the API for an in-depthdescription.

Note

The Neos \ Mistake \ Messages \ Outcome object has actually been presented so as to make even more structured inaccuracy result feasible –- whichis actually particularly needed to have when items along withsub-properties ought to be actually confirmed recursively.

Creating Validator Occasions: The ValidatorResolver

As validators could be bothsingleton or even model things (relying if they possess interior state), you need to not instantiate them straight as it has been carried out in the above example. As an alternative, you must use the \ Neos \ Flow \ Validation \ ValidatorResolver individual to receive a new circumstances of a specific validator:

 $ validatorResolver  ->>  createValidator ($ validatorType , variety $ validatorOptions  );.

$validatorType could be among the following:

The $validatorOptions guideline is a concomitant range of validator choices. See the validator endorsement in the appendix for the configuration alternatives of the integrated validators.

Default Validators

Flow is actually shipped witha significant list of validators whichare ready to make use of –- see the appendix for the complete list. Here, our team merely wishto highlight some even more exclusive validators.

Additional to the straightforward validators for strings, varieties and various other general types, Circulation possesses a handful of effective validators delivered:

SHARE