PHP code example of ebidtech / validator

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

    

ebidtech / validator example snippets


use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Constraints\Type;

class Test {
    public function getByName($name)
    {
        $violations = Validation::createValidator()->validateValue(
            $name,
            new Type(array('type' => 'string'))
        );

        if (count($violations) != 0) {
          throw new \InvalidArgumentException((string) $violations);
        }
    }
}

use EBT\Validator\ValidatorBasicExtended;

class Test {
    public function getByName($name)
    {
        if (!ValidatorBasicExtended::isTypeString($name)) {
            throw new \InvalidArgumentException(ValidatorBasicExtended::getViolationsAsShortString());
        }
    }
}