Skip to content

1056ng/Iapetus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phalcon Json Schema Validator Plugin

A simple plugin to validate parameter from Request in PHP with justinrainbow/json-schema.

Installation

Use composer to manage your dependencies and download:

{
    "repositories": [
      {
        "type": "vcs",
        "url": "https://github.com/1056ng/Iapetus"
      }
    ],
    "require": {
      "1056ng/Iapetus": "~1.0"
    }
}

Example

setup

$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach(\Iapetus\EventKeys::prefix, new \Iapetus\Middleware());
$app->setEventsManager($eventsManager);

check

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]);
}