dsxwk/hyperf-helper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

dsxwk/hyperf-helper

最新稳定版本:v1.1.0

Composer 安装命令:

composer require dsxwk/hyperf-helper

包简介

Hyperf Framework Assistant

README 文档

README

安装

composer require dwxwk/hyperf-helper

验证器

继承BaseFormRequest类,实现sceneRule方法,返回验证场景规则, 支持每个场景自定义字段验证,满足更复杂验证。官方的公共rules方法,无法满足复杂验证场景。如创建某个字段必填,但是更新相同的字段又不需要验证或者使用其他验证,增加了灵活性。

<?php

declare(strict_types=1);

namespace App\Request;

use Dsxwk\Framework\HyperfHelper\Request\BaseFormRequest;

class IndexRequest extends BaseFormRequest
{
    /**
     * 验证场景规则
     *
     * @return array
     */
    public function sceneRules(): array
    {
        return [
            // 创建
            'create'               => [
                'remark'      => 'nullable|string',
                'attachments' => 'array',
                // ...
            ],
            // 更新
            'update'               => [
                'id'          => 'required|integer|gt:0',
                'remark'      => 'nullable|string',
                'attachments' => 'array',
                // ...
            ],
        ];
    }

    /**
     * 提示字段设置
     *
     * @return string[]
     */
    public function attributes(): array
    {
        return [
            'id'                         => 'ID',
            'remark'                     => '备注',
            'attachments'                => '附件',
        ];
    }
}

控制器

<?php

declare(strict_types=1);

namespace App\Controller;

use App\Request\IndexRequest;
use Hyperf\Di\Annotation\Inject;

class IndexController
{
    #[Inject]
    public IndexRequest $indexRequest;

    public function create()
    {
        // 验证场景
        $this->indexRequest->scene('create')->validateResolved();
        // ...
    }
    
    public function update()
    {
        // 验证场景
        $this->indexRequest->scene('update')->validateResolved();
        // ...
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-11-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固