PHP code example of mittwald / psr7-validation

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

    

mittwald / psr7-validation example snippets


$app->post('/customers', $handler)
    ->add(new ValidationMiddleware(
        Factory::buildJsonValidatorFromUri('path/to/json-schema.json')
    ));

$app->post('/customers', $handler)
    ->add(new ValidationMiddleware(
        Factory::buildJsonValidatorFromSwaggerDefinition('path/to/swagger.json', 'MyType')
    ));

$app->post('/customers', $handler)
    ->add(new ValidationMiddleware(
        new class implements ValidatorInterface {
            public function validateJson($jsonDocument, ValidationResult $result) {
                $result->addErrorForProperty('customernumber', 'Foo');
            }
        }
    ));

$app->post('/customers', $handler)
    ->add(new ValidationMiddleware(
        new CombinedValidator(
            Factory::buildJsonValidatorFromUri('path/to/schema.json'),
            new MyVerySpecialCustomValidator()
        )
    ));