PHP code example of xervice / validator

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

    

xervice / validator example snippets


use Xervice\Validator\Business\Dependency\ValidatorConfigurationProviderPluginInterface;
use Xervice\Validator\Business\Model\ValidatorType\IsType;

class TestValidatorConfig implements ValidatorConfigurationProviderPluginInterface
{
    /**
     * @return array
     */
    public function getValidatorConfiguration(): array
    {
        return [
           'unit',
           'floatTest',
           'child',
           [
               'unit' => [
                   'type' => IsType::TYPE_INTEGER
               ],
               'floatTest' => [
                   'type' => IsType::TYPE_FLOAT
               ]
           ],
           [
               'isTest' => [
                   '
}

class ExamplePlugin extends AbstractBusinessPlugin implements ValidatorTypePluginInterface
{
    protected const NAME = 'ExamplePlugin';

    /**
     * @return string
     */
    public function getTypeName(): string
    {
        return static::NAME;
    }

    /**
     * @param mixed $config
     *
     * @return bool
     */
    public function isResponsible($config): bool
    {
        return true;
    }

    /**
     * @param array $data
     * @param string $key
     * @param mixed $config
     */
    public function validate(array $data, string $key, $config): void
    {
        if (<is-not-valid>) {
            throw new ValidatorException('Foo is not valid because!');
        }
    }
}