2 Star 5 Fork 2

Saopig / imi-validate

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
MIT

Imi-Validate

安装:composer require phpben/imi-validate

抽离Thinkphp6的validate验证器,可以在Imi上使用 手动验证(看tp6官方文档)及 注解验证
使用方法与tp无异

注解使用方式

注解:@Validate
参数:
var=注入到方法中的变量名称
class=验证器类名,默认会自动取Controller同级目录下的Validate/xxxValidate.php
scene=场景名称,默认使用验证器内的场景
security=安全过滤所有参数,设置为false则为原参数内容
fitler=是否过滤多余参数,假如验证器规则有username,password,但是接口传入了username,password,xxx ,默认会把xxx过滤掉,设为false为不过滤

控制器
使用Validate注解,验证后的数据会自动注入到方法的data参数中,注入的变量为智能数组对象 支持对象与数组调用

<?php

declare(strict_types=1);

namespace ImiApp\ApiServer\Backend\Controller;

use Imi\Server\Http\Controller\HttpController;
use Imi\Server\Http\Route\Annotation\Action;
use Imi\Server\Http\Route\Annotation\Controller;
use Imi\Server\Http\Route\Annotation\Route;


use Phpben\Imi\Validate\Annotation\Validate;

/**
 * @Controller("/test/")
 */
class TestController extends HttpController
{
    /**
     * @Action
     * @Route(url="login",method="POST")
     *
     *
     * @Validate
     */
    public function login($data)
    {
        return $data;
    }
    
}
// 更多使用方式
// @Validate(var="params",class="ImiApp\ApiServer\Validate",scene="test",security="false",fitler="false")



验证器

<?php

declare(strict_types=1);

namespace ImiApp\ApiServer\Backend\Validate;

use Phpben\Imi\Validate\Validate;

class AuthValidate extends Validate
{
    protected $rule =   [
        'password'  => 'require',
        'as'  => 'require',
    ];

    protected $message  =   [
        'password.require' => '名称必须',
    ];

    // 场景设置,不设置则使用所有规则验证,与thinkphp设置无异
    protected $scene = [
        'login'=>['password']
    ];
}

就这么简单啦,手动验证看thinkphp文档即可
MIT License Copyright (c) 2021 Saopig Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

基于thinkphp-validate的验证器,可以在imi上注解验证 expand collapse
PHP
MIT
Cancel

Releases (12)

All

Contributors

All

Activities

Load More
can not load any more
1
https://gitee.com/phpben/imi-validate.git
git@gitee.com:phpben/imi-validate.git
phpben
imi-validate
imi-validate
master

Search

53164aa7 5694891 3bd8fe86 5694891