定制 renegare/aiv 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

renegare/aiv

Composer 安装命令:

composer require renegare/aiv

包简介

api input validator (with support for Silex)

README 文档

README

Build Status Coverage Status

Requirements

  • PHP 5.4
  • composer (preferably latest)

Installation

$ composer require renegare/aiv:dev-master

Usage Examples:

Silex Usage

<?php

$app = new \Silex\Application();
$app->register(new \AIV\Integration\SilexProvider, [
    'aiv.validators' => [
        'test-name' => [
            'options' => [
                'allow.extra.params' => true,
                'allow.missing.params' => true
            ],
            'params' => [
                'name' => [
                    'not.blank',
                    [
                        'type' => 'length',
                        'options' => ['min' => 2, 'max' => 20]]],
                'email' => ['not.blank', '%email.validator%'],
                'password' => ['not.blank']]]]]);

$app['email.validator'] = $app->share(function() {
    return new \Symfony\Component\Validator\Constraints\Email;
});

$app->post('/', function(Application $app) {
    
    $apiValidator = $app['validator'];

    if($apiValidator->hasErrors('test-name')) {

        $errors = [];
        foreach($apiValidator->getErrors('test-name') as $violation) {
            $path = preg_replace('/[\[\]]/', '', $violation->getPropertyPath());
            $errors[$path] = $violation->getMessage();
        }
        return sprintf('You have errors: <pre>%s</pre>', print_r($errors, true));

    } else {

        return sprintf('You sent me valid data:<br /><pre>%s</pre>', print_r($apiValidator->getData('test-name'), true));
    }
});

$app->run();

JSON Input

Typical JSON Rest API applications take input from the body in the form of json. There the default input handler will not work as it effectively looks in the $_POST array.

Simply add this code after registering the provider:

$app['aiv.input'] = $this->share(function(){
    new \AIV\Input\SymfonyRequest\JSONInput;
});

Test

Check out the repo and from the top level directory run the following command (xdebug required for coverage):

$ composer update && vendor/bin/phpunit --coverage-text

Road Map

  • "Modelesque" Classes that represent validation requirements ($instance_variables vs annotations)

Behind The Scene Lib

The actual validation of data is handled by: Symfony/Validator Component

统计信息

  • 总下载量: 378
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-06-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固