定制 tbaronnat/api-validation-rules-bundle 二次开发

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

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

tbaronnat/api-validation-rules-bundle

最新稳定版本:1.0.0

Composer 安装命令:

composer require tbaronnat/api-validation-rules-bundle

包简介

System to get all validation rules by validation groups for each api endpoint

README 文档

README

Description

This project provides a system to get all validation rules by validation groups for each API endpoint. It includes methods to retrieve validation rules for all API routes.

Features

  • Retrieve validation rules for all API routes.

Installation

Install dependencies using Composer:

   composer require tbaronnat/api-validation-rules-bundle

Usage

Retrieve Validation Rules for API Routes

To retrieve validation rules for all API routes, use the getValidationRules method:

$validationRules = $mainValidationRulesProvider->getValidationRules();

Override method isValidEntityGroup on EntityGroupApiProvider

Actually, the method isValidEntityGroup(string $group): bool is used to check if the group is valid for api validation. 
You can override this method to add your own logic.
Group is valid if the name contains "api:[...]"

Override method isValidApiRoute on RouteApiProvider

Actually, the method isValidApiRoute(string $route): bool is used to check if the route is valid for api validation. 
You can override this method to add your own logic.
Route is valid if the name contains "api_"

Override method getValidationGroupsForRoute on RouteValidationGroupsProvider

Actually, the method getValidationGroupsForRoute(string $route): array is used to get the validation groups for a route. 
You can override this method to add your own logic (for example, get validation groups from annotation if you use ApiPlatform).)
Validation groups are retrieved from configuration option "validation_groups" for the route.
Exemple of configuration:

```yaml
routes:
    api_users_create:
        path: api/user/create
        methods: [GET, POST]
        options:
            validation_groups: ["api:user_validation:create"]

```

Return example

```json
{
  "api_users_create": {
    "api:user_validation:create": {
      "lastName": [
        {
          "type": "notblank",
          "payload": null,
          "groups": ["api:user_validation:create"],
          "message": "The name should not be blank.",
          "allowNull": false,
          "normalizer": null
        }
      ]
    }
  }
}
```

License

This project is licensed under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-28