Blazing fast data modeling with Symfony

View on GitHub
Fork me on GitHub


The EAV model is 100% compatible with Symfony's validator component.

Validating attributes

There is an existing mechanism that loads automatically validation constraints defined in the model declaration.

            attributeAsLabel: name
                    # This is equivalent to using the NotBlank validator
                    required: true 

                        - Email:
                            message: "The email '{{ value }}' is not a valid email."
                            checkMX: true

You can use any native Symfony constraint or use custom constraints with the same syntax than the traditional YAML syntax.

See the full Symfony Validation Constraints Reference

Class constraints validation

Sometimes you want to implements a validation constraint directly on the family and not on a single attribute.

This is currently not supported in the model definition but can be achieved by defining a dedicated class for a given family. See 12 - Custom classes

Simply use the existing mechanism to declare class constraints in Symfony

Using validation groups

Because we can't declare a validation constraints that matches every validation group in Symfony, we need to declare every new validation group in the Data class like this:


namespace MyNamespace\EAVModelBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Sidus\EAVModelBundle\Entity\AbstractData;
use Sidus\EAVModelBundle\Validator\Constraints\Data as DataConstraint;

 * @ORM\Table(...)
 * @ORM\Entity(...)
 * @DataConstraint(groups={"custom_group_1", "custom_group_2", "..."})
class Data extends AbstractData
You can't use custom validation groups in attribute constraints definitions without declaring them like this