PHP code example of pklink / validator-chain

1. Go to this page and download the library: Download pklink/validator-chain 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/ */

    

pklink / validator-chain example snippets




$chain = \Validation\Chain('check me');

$chain
    ->isString()  // return instance of Chain
    ->isInteger() // return instance of Chain
    ->isArray()   // return instance of Chain
;

$chain->isValid(); // return false

(new \Validation\Chain('check me'))
    ->isString()
    ->isInteger()
    ->isArray()
    ->isValid()

$chain = new \Validator\Chain('value');

$chain->isInteger()->isString()->isValid(); // returns false
$chain->isValid();                          // returns false
$chain->isString()->isValid();              // returns false
$chain->reset()->isString()->isValid();     // returns true

$chain = new \Validator\Chain('value', ['option' => 'value']);

$chain = new \Validator\Chain('value', ['throwExceptionOnFailure' => true]);

try {
    $chain
        ->isString()         // everything fine
        ->minimumLengthOf(2) // everything fine
        ->isArray()          // \Validator\Exception will be thrown
        ->isArray();         // will not perform
} catch (\Validator\Excetion $e) {
    echo 'validation failed!';
}

$chain->throwExceptionOnFailure(true);
$chain->throwExceptionOnFailure(false);
$chain->throwExceptionOnFailure(); // set this option to true

$chain = new \Validator\Chain('value', ['stopValidationOnFailure' => true]);

$chain
    ->isString()    // everthing fine
    ->isArray()     // validation fail
    ->isInteger();  // will not perform

$chain->stopValidationOnFailure(true);
$chain->stopValidationOnFailure(false);
$chain->stopValidationOnFailure(); // set this option to true

$chain = new \Validator\Chain('value');

$chain->addValidationFailureListener(function() {
    echo 'failure';
});

$chain->isInteger();

$chain->addValidationFailureListener(function(\Validation\Rule $rule) {
    echo get_class($rule);
});
sh
php composer.phar install
sh
php composer.phar install --dev
php vendor/bin/phpunit tests/
sh
php composer.phar install --dev
php vendor/bin/phpunit --coverage-html output tests/