Skip to content

Using validation annotations in doctrine entity #57

Closed
portphp/steps
#10

Description

@Glideh

When using a doctrine writer, is there a way to take advantage of the doctrine annotations already there ?

// Doctrine entity class
/**
 * @var string
 *
 * @ORM\Column(type="string", length=150, nullable=false)
 * @Assert\NotBlank
 */
private $name;

So we don't have to redefine them in a ValidatorFilter.
Or do we have to use reflection to inject them into ValidatorFilters ?

Activity

  1. ddeboer commented on Sep 8, 2017

    @ddeboer
    Member

    You’re talking about the @Assert\NotBlank, right? Actually, that’s not Doctrine-specific, but a more generic (Symfony) validation constraint.

    What you’re then asking for, is a way to validate some PHP object with annotations. This should be as simple as:

    $errors = $validator->validate($yourObject);

    Perhaps we could add this to our ValidatorStep.

  2. Glideh commented on Sep 8, 2017

    @Glideh
    Author

    I forgot these constraints were Symfony ones. Yes I was talking about the Assert one.
    Using a StepAggregator where can I validate the object already transformed ?
    I could override __invoke in ValidatorFilter but it receives the array.

  3. changed the title [-]Triggering doctrine validation annotations[/-] [+]Using validation annotations in doctrine entity[/+] on Sep 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions