PHP code example of ride / lib-validation

1. Go to this page and download the library: Download ride/lib-validation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ride / lib-validation example snippets




use ride\library\validation\factory\ValidationFactory;

function foo(ValidationFactory $factory) {
    $trimFilter = $factory->createFilter('trim');
    $ion');
    $constraint->addValidator($



use ride\library\validation\factory\ValidationFactory;

function foo(ValidationFactory $factory) {
    $constraint = $factory->createConstraint('or');
    $constraint->addProperty('firstName');
    $constraint->addProperty('displayName');
    
    // optionally, you can override the default error code
    $constraint->setError('error.validation.custom');
    
    return $constraint;
}



use ride\library\validation\factory\ValidationFactory;

function foo(ValidationFactory $factory) {
    $constraint = $factory->createConstraint('equals');
    $constraint->addProperty('password');
    $constraint->addProperty('repeatPassword');
    
    // optionally, you can override the default error code
    $constraint->setError('error.validation.custom');
    
    return $constraint;
}



use ride\library\validation\factory\ValidationFactory;

function foo(ValidationFactory $factory) {
    $url');
    $constraint->addValidator($



use ride\library\validation\factory\ValidationFactory;

function createConstraint(ValidationFactory $factory) {
    $trimFilter = $factory->createFilter('trim');
    $neralConstraint->addFilter($trimFilter, 'name');
    $generalConstraint->addFilter($trimFilter, 'description');
    $generalConstraint->addValidator($;
    $typeUrlConstraint->addValidator($hain->addConstraint($typeNodeConstraint);
    
    return $chain;
}



use ride\library\validation\exception\ValidationException;
use ride\library\validation\factory\ValidationFactory;

function foo(ValidationFactory $factory) {
    // filter some values
    $trimFilter = $factory->createFilter('trim');
    
    $result = $trimFilter->filter(null); // null
    $result = $trimFilter->filter($trimFilter); // $trimFilter
    $result = $trimFilter->filter('  My Title  '); // 'My Title'
    
    // validate some values
    $sample for the chain build up
    $constraint = createConstraint($factory);
    
    try {
        $result = $contraint->constrain($data);
    } catch (ValidationException $exception) {
        // url is