PHP code example of renegare / aiv

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

    

renegare / aiv example snippets




$app = new \Silex\Application();
$app->register(new \AIV\Integration\SilexProvider, [
    'aiv.validators' => [
        'test-name' => [
            'options' => [
                'allow.extra.params' => true,
                'allow.missing.params' => true
            ],
            'params' => [
                'name' => [
                    'not.blank',
                    [
                        'type' => 'length',
                        'options' => ['min' => 2, 'max' => 20]]],
                'email' => ['not.blank', '%email.validator%'],
                'password' => ['not.blank']]]]]);

$app['email.validator'] = $app->share(function() {
    return new \Symfony\Component\Validator\Constraints\Email;
});

$app->post('/', function(Application $app) {
    
    $apiValidator = $app['validator'];

    if($apiValidator->hasErrors('test-name')) {

        $errors = [];
        foreach($apiValidator->getErrors('test-name') as $violation) {
            $path = preg_replace('/[\[\]]/', '', $violation->getPropertyPath());
            $errors[$path] = $violation->getMessage();
        }
        return sprintf('You have errors: <pre>%s</pre>', print_r($errors, true));

    } else {

        return sprintf('You sent me valid data:<br /><pre>%s</pre>', print_r($apiValidator->getData('test-name'), true));
    }
});

$app->run();


$app['aiv.input'] = $this->share(function(){
    new \AIV\Input\SymfonyRequest\JSONInput;
});