PHP code example of ddrv / dresscode

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

    

ddrv / dresscode example snippets




use Ddrv\DressCode\Action;
use Ddrv\DressCode\DressCode;

put(), ['type' => 'string'], 'it is ok');



use Ddrv\DressCode\Action;
use Ddrv\DressCode\DressCode;
use Ddrv\DressCode\Exception\InvalidValueException;
       'type' => 'string',
            'format' => 'email',
        ],
        'login' => [
            'type' => 'string',
            'minLength' => 5,
            'maxLength' => 32,
            'pattern' => '^[a-z\-]+$',
        ],
        'birthday' => [
            'type' => 'string',
            'format' => 'date',
        ],
    ],
    'rthday: 2020-02-30 is not a date
*/



use Ddrv\DressCode\Action;
use Ddrv\DressCode\DressCode;

/email', [
    'type' => 'string',
    'format' => 'email',
]);
$validator->setEntity('#/entities/login', [
    'type' => 'string',
    'minLength' => 5,
    'maxLength' => 32,
    'pattern' => '^[a-z\-]+$',
]);
$validator->setEntity('#/entities/date', [
    'type' => 'string',
    'format' => 'date',
]);

$rule = [
    'type' => 'object',
    'properties' => [
        'email' => [
            '$ref' => '#/entities/email',
        ],
        'login' => [
            '$ref' => '#/entities/login',
        ],
        'birthday' => [
            '$ref' => '#/entities/date',
        ],
        'password' => [
            'type' => 'string',
            'minLength' => 8,
            'maxLength' => 32,
            'writeOnly' => true,
        ],
    ],
    '



use Ddrv\DressCode\Action;
use Ddrv\DressCode\Exception\WrongFormatException;
use Ddrv\DressCode\Format\Format;
use Ddrv\DressCode\DressCode;

$value, FILTER_VALIDATE_EMAIL) !== false) {
            throw new WrongFormatException('email');
        }
    }
};
$validator->registerFormat('email', $myEmailFormat);

$rule = [
    'type' => 'string',
    'format' => 'email',
];
$validator->validate(Action::input(), $rule, '[email protected]');