项目作者: 1056ng

项目描述 :
Phalcon Json Schema Validator Plugin
高级语言: PHP
项目地址: git://github.com/1056ng/Iapetus.git
创建时间: 2017-10-06T05:19:35Z
项目社区:https://github.com/1056ng/Iapetus

开源协议:MIT License

下载


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:

  1. {
  2. "repositories": [
  3. {
  4. "type": "vcs",
  5. "url": "https://github.com/1056ng/Iapetus"
  6. }
  7. ],
  8. "require": {
  9. "1056ng/Iapetus": "~1.0"
  10. }
  11. }

Example

setup

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

check

  1. function beforeExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Di\Injectable $injectable) {
  2. $di = $this->getDi();
  3. $body = $di->getRequest()->getJsonRawBody();
  4. $schemaPath = '/var/www/xxx/xxxxx.json';
  5. $di->getEventsManager()->fire(\Iapetus\EventKeys::check, $injectable, ['data' => $body, 'schema' => $schemaPath]);
  6. }