1. Go to this page and download the library: Download danack/params 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/ */
danack / params example snippets
$rules = [
'limit' => [
new CheckSetOrDefault(10, $variableMap),
new IntegerInput(),
new MinIntValue(0),
new MaxIntValue(100),
],
'offset' => [
new CheckSetOrDefault(null, $variableMap),
new SkipIfNull(),
new MinIntValue(0),
new MaxIntValue(1000000),
],
];
list($limit, $offset) = Params::validate($params);
$validator = new ParamsValidator();
$limit = $validator->validate('limit', [
new CheckSetOrDefault(10, $variableMap),
new IntegerInput(),
new MinIntValue(0),
new MaxIntValue(100),
]);
$offset = $validator->validate('offset', [
new CheckSetOrDefault(null, $variableMap),
new SkipIfNull(),
new MinIntValue(0),
new MaxIntValue(1000000),
]);
$errors = $validator->getValidationProblems();
if (count($errors) !== 0) {
// return an error
return [null, $errors];
}
// return an object with null
return [new GetArticlesParams($order, $limit, $offset), null];