Symfony2 - Validation.yml with class and extended class

I have 'addressClass' and 'shippingAddressClass'. ShippingAdress extends the address, and both confirm identity. EXCEPT "shippingAddress" is not valid when a PO Box is detected. Although the mailbox is the correct billing address, UPS does not send them.

Hypothetically, what is the best SF2 practice for checking Bird , which extends Animal ?

Should we duplicate the .yml we used to validate Animal ? Essentially giving us two fairly identical sections (see below). In this case, getters slightly different from Animal to Bird , but properties require fairly identical validation rules.

 Acme\BlogBundle\Entity\Animal: properties: name: - NotBlank: ~ getters: isAnimal: - "True" Acme\BlogBundle\Entity\Bird: properties: name: - NotBlank: ~ getters: isAnimal: - "True" isBird - "True" 
+4
source share
1 answer

The validator service is intelligent and checks for class restrictions of origin. Therefore, in my example Animal , Bird we need only:

 Acme\BlogBundle\Entity\Animal: properties: name: - NotBlank: ~ getters: isAnimal: - "True" Acme\BlogBundle\Entity\Bird: getters: isBird - "True" 
+1
source

Source: https://habr.com/ru/post/1447551/


All Articles