2017 © Pedro Peláez
 

library validate-embedded

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

image

fluoresce/validate-embedded

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

  • Monday, October 30, 2017
  • by jaikdean
  • Repository
  • 1 Watchers
  • 3 Stars
  • 25,549 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 9 % Grown

The README.md

Validate Embedded

This library provides the Validate constraint for the Symfony Validator Component., (*1)

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)., (*2)

Installation

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

$ composer require fluoresce/validate-embedded

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

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, (*5)

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., (*6)

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

<?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., (*8)

<?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., (*9)

Combining All Options

This example combines behaviour from the previous ones to show how it operates together., (*10)

<?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;
}

The Versions

30/10 2017

dev-master

9999999-dev https://github.com/fluoresceco/validate-embedded

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

  Sources   Download

MIT

The Requires

 

by Jaik Dean

validator validation symfony2 symfony3 validate constraint symfony4

30/10 2017

1.1.0

1.1.0.0 https://github.com/fluoresceco/validate-embedded

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

  Sources   Download

MIT

The Requires

 

by Jaik Dean

validator validation symfony2 symfony3 validate constraint symfony4

11/04 2016

1.0.1

1.0.1.0 https://github.com/fluoresceco/validate-embedded

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

  Sources   Download

MIT

The Requires

 

by Jaik Dean

validator validation symfony2 symfony3 validate constraint

07/04 2016

1.0.0

1.0.0.0 https://github.com/fluoresceco/validate-embedded

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

  Sources   Download

MIT

The Requires

 

by Jaik Dean

validator validation symfony2 symfony3 validate constraint