承接 fengdangxing/hyperf-validator-quote 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

fengdangxing/hyperf-validator-quote

最新稳定版本:v1.1.9

Composer 安装命令:

composer require fengdangxing/hyperf-validator-quote

包简介

hyperf-validator封装应用层

README 文档

README

####简版使用-主要增加自定义方法 放在验证类处理 validation

#配置路径 config/annotations.php 没有改文件新建
return [
    'scan' => [
        'paths' => [
            BASE_PATH . '/app',
            BASE_PATH . '/vendor/fengdangxing',//增加该配置
        ],
        'ignore_annotations' => [
            'mixin',
            'Notes',
            'Author',
            'Data',
            'Date'
        ],
    ],
];

#继承基础类

namespace App\Validator;

use Fengdangxing\ValidatorQuote\ValidatorQuote;
use Hyperf\Validation\Validator;


class PublishValidator extends ValidatorQuote
{
    protected $scenes = [
        'publish' => ['id', 'mark'],
        'publish_retry' => ['id'],
        'addBatch' => ['merchant_site_id', 'merchant_page_id', 'mark']
    ];

    protected $extendList = ['check_publish'];

    protected $rules = [
        'merchant_site_id' => 'required|check_publish',
        'mark' => 'max:1000',
        'merchant_page_id' => 'check_type_empty',
        'merchant_component_id' => 'check_type',
        'merchant_color_id' => 'check_type',
        'id' => 'required',
    ];

    protected $messages = [
        'merchant_site_id.required' => "1000|merchant_site_id is empty",//code|message
        'id.required' => "1001|id is empty",
        'mark.max' => "1002|mark is empty",
        'merchant_page_id.check_type_empty' => "1003|merchant_page_id is empty",
        'merchant_site_id.check_publish' => "1004|check_publish"
    ];

    protected $filter = [
        'mark' => 'fliter_sql|fliter_str',
    ];

    public function check_publish($attribute, $value, $parameters, Validator $validator)
    {
        return true;
    }
}

#控制器

namespace App\Controller;

use Fengdangxing\ValidatorQuote\Annotation\ValidatorQuote;

class IndexController extends AbstractController
{
    /**
     * @VQ(class="\App\Validator\PublishValidator::class",scene="publish")
     */
    public function index()
    {
        $user = $this->request->input('user', 'Hyperf');
        $method = $this->request->getMethod();
        return [
            'method' => $method,
            'message' => "Hello {$user}.",
        ];
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-30