php - How can I add a custom Validator to Respect's Validation library -


Awesome comes with many underlying assumptions, such as strings (), alpha (), etc. I want to add self-defined beliefs to the library, for example, I want to be able to:

  Validator :: myCustomValidator () - & gt; Emphasis ($ input); I just got to know that this is not very complicated, but I had to look at the source code of the library to find out, so I posted self answer questions here for future reference. I am doing /P>  

Define a verification class in the appropriate namespace and the exception class together, and the verification library automatically They will use them to validate their data, such as:

myCustomValidator.php:

  & lt ;? Php namespace respect \ validation \ rules; Class myCustomValidator AbstractRule {Validates the public function (IN $ input) {true back; // apply actual check here; Such as: return is_string ($ input); }}   

myCustomValidatorException.php:

  & lt ;? Php namespace respect \ validation \ exception; Class myCustomValidatorException Validation Upstation {Public Fixed $ Default templates = array (self :: MODE_DEFAULT => array (self :: standard => '{{name}} should ...', // eg: string should be ), Auto :: MODE_NEGATIVE => array (self :: standard => should not be '{{name}} ...', // example: string should not be)); }   

Unless these files are included in your project, verifier: myCustomValidator () - & gt; Emphasis ($ input); should work now.

This is clearly dependent on naming conventions, so be sure to use the class name to make self-defined verifier calls and you should set.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -