A simple plugin to validate parameter from Request in PHP with justinrainbow/json-schema.
Use composer to manage your dependencies and download:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/1056ng/Iapetus"
}
],
"require": {
"1056ng/Iapetus": "~1.0"
}
}
$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach(\Iapetus\EventKeys::prefix, new \Iapetus\Middleware());
$app->setEventsManager($eventsManager);
function beforeExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Di\Injectable $injectable) {
$di = $this->getDi();
$body = $di->getRequest()->getJsonRawBody();
$schemaPath = '/var/www/xxx/xxxxx.json';
$di->getEventsManager()->fire(\Iapetus\EventKeys::check, $injectable, ['data' => $body, 'schema' => $schemaPath]);
}