fluoresce/validate-embedded 问题修复 & 功能扩展

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

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

fluoresce/validate-embedded

最新稳定版本:1.3.0

Composer 安装命令:

composer require fluoresce/validate-embedded

包简介

Constraint enabling group-based validation of embedded objects with the Symfony Validator Component.

README 文档

README

This library provides the Validate constraint for the Symfony Validator Component.

This constraint behaves similar to the built-in Valid constraint, but respects the groups option. Additionally, it adds an option to specify the validation groups to target on the embedded object(s).

Installation

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require fluoresce/validate-embedded

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Documentation

The following examples assume you are using the full Symfony framework, though this package can be used in any project that has the Symfony Validator Component available

Basic Usage

This example shows an Author which has a collection of Books. When validation is run for group1 on Author, it will cascade to all embedded Book instances.

The behaviour here is slightly different to the standard Valid constraint, as validation of the Book instances is run with the default group.

<?php use Fluoresce\ValidateEmbedded\Constraints as Fluoresce; class Author { /**  * @var Book[]  * @Fluoresce\Validate(groups={"group1"});  */ private $books; }
<?php use Symfony\Component\Validator\Constraints as Assert; class Book { /**  * @var string  * @Assert\NotBlank()  */ private $title; }

Specifying Embedded Validation Groups

Imagine we want to specify different validation groups to be run on the Book instances. We can target these by specifying them in the Validate annotation.

<?php use Fluoresce\ValidateEmbedded\Constraints as Fluoresce; class Author { /**  * @var Book[]  * @Fluoresce\Validate(embeddedGroups={"bookgroup1"});  */ private $books; }
<?php use Symfony\Component\Validator\Constraints as Assert; class Book { /**  * @var string  * @Assert\NotBlank(groups={"bookgroup1"})  */ private $title; }

Now whenever an Author instance is validated, the embedded Books will be validated with validation group bookgroup1.

Combining All Options

This example combines behaviour from the previous ones to show how it operates together.

<?php use Fluoresce\ValidateEmbedded\Constraints as Fluoresce; class Author { /**  * @var Book[]  * @Fluoresce\Validate(groups={"group1"}, embeddedGroups={"bookgroup1"});  */ private $books; }
<?php use Symfony\Component\Validator\Constraints as Assert; class Book { /**  * @var string  * @Assert\NotBlank(groups={"bookgroup1"})  */ private $title; }

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固