It looks like symfony tries to help you out a lot with Validation but I am a bit confused. I have an Address object that looks like this
/**
* @ORM\Entity
* @ORM\Table(name="address")
*/
class Address {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
* @var int $id
*/
private $id;
/**
* @ORM\Column(name="street1", type="string", nullable=true)
* @var string $street1
*/
private $street1;
/**
* @ORM\Column(name="street2", type="string", nullable=true)
* @var string $street2
*/
private $street2;
/**
* @ORM\Column(name="street3", type="string", nullable=true)
* @var string $street3
*/
private $street3;
/**
* @ORM\Column(name="city", type="string", nullable=true)
* @var string $city
*/
private $city;
/**
* @ORM\Column(name="state", type="string", nullable=true)
* @var string $state
*/
private $state;
/**
* @ORM\Column(name="zip", type="integer", nullable=true)
* @var integer $zip
*/
private $zip;
/**
* @var AddressType
* This is only used for previous addresses
* @DoctrineAssert\Enum(entity="RLD\AppBundle\DBAL\AddressType")
* @ORM\Column(name="address_type", type="AddressType", nullable=true)
*/
private $addressType;
}
I am using this object twice. Once for Current address and another time for previous address. The problem is I only need the info for previous address if the user hasn't been in the current address for more than 5 years. I suspect I am going to need to extend the class in order to get what I want working. However even after extending I am not sure how to make conditional validation.
The Question
How do you make conditional validation?
if(currentAddress < 5)
validate previous address;
Anyone have ideas for this? This form seems to carry a common theme across it that needs this functionality. Any help/suggestions would be appreciated.