PHP code example of isholao / prove

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

    

isholao / prove example snippets




 = [
    'name' => 'Ishola O',
    'age' =>'100'
];

$prover = new \Prove\Prover($data);
$prover->



class CustomRule extends \Prove\AbstractRule 
{
    function __construct()
    {
        $this->name = 'customrule';
    }

    public function __invoke(?string $message = NULL)
    {
        $this->message = $message ?? 'Custom error goes here';
    }

    public function validate(&$val): bool
    {
        return true or false
    }
}

$data = [
    'name' => 'Ishola O',
    'age' =>'100'
];

$prover = new \Prove\Prover($data);
$prover->addRule(new CustomRule());
$prover->addRule(new class extends \Prove\AbstractRule
        {

            public function __construct()
            {
                $this->name = 'custom';
            }

            public function __invoke(?string $message = NULL)
            {
                $this->message = $message ?? 'Custom error goes here.';
            }

            public function validate(&$val): bool
            {
                return false;
            }
        });
$prover->customrule('optional error message goes here or use default')->validate('name','Label goes here');