2 Star 5 Fork 2

Saopig/imi-validate

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
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.

简介

基于thinkphp-validate的验证器,可以在imi上注解验证 展开 收起
PHP
MIT
取消

发行版 (12)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/phpben/imi-validate.git
git@gitee.com:phpben/imi-validate.git
phpben
imi-validate
imi-validate
master

搜索帮助

Cb406eda 1850385 E526c682 1850385