PHP code example of klapuch / validation

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

    

klapuch / validation example snippets


(new EmptyRule())->satified('abc'); // false
(new EmptyRule())->satified(''); // true
(new EmptyRule())->apply('abc'); // \UnexpectedValueException - 'Subject is not empty'
(new FriendlyRule(new EmptyRule(), 'Not empty!'))->apply('abc'); // \UnexpectedValueException - 'Not empty!'

(new ChainedRule(
	new FriendlyRule(
		new NegateRule(new EmptyRule()),
		'Value can not be empty'
	),
	new LengthRule(10),
	new PassiveRule, // it does nothing
	new EmailRule(),
))->apply('abc');