PHP code example of gd-75 / request-body-validator
1. Go to this page and download the library: Download gd-75/request-body-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/ */
$validator = new RequestBodyValidator($request->getParsedBody());
if(
$validator->validateMultiple(["field1", "field4"], RequestBodyValidator::EXISTS)
&& $validator->validateMultiple(["field", "field2"], RequestBodyValidator::NOT_EMPTY)
&& $validator->validateOne("field3", RequestBodyValidator::NUMERIC)
){
// Do stuff
}
// Constructor, $request is your PSR-7 request object
$validator = new RequestBodyValidator($request->getParsedBody());
// validateOne, validates a single field
$validator->validateOne($name, $criteria);
// validateMultiple, validates multiple fields with the same criteria
$validator->validateMultiple([$name, $name1], $criteria);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.