/** * Validates the object and all objects related to this table. * * @see getValidationFailures() * @param object $validator A Validator class instance * @return boolean Whether all objects pass validation. */ public function validate(Validator $validator = null) { if (null === $validator) { $validator = new Validator(new ClassMetadataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory(), new DefaultTranslator()); } $failureMap = new ConstraintViolationList(); if (!$this->alreadyInValidation) { $this->alreadyInValidation = true; $retval = null; // We call the validate method on the following object(s) if they // were passed to this object by their corresponding set // method. This object relates to these object(s) by a // foreign key reference. // If validate() method exists, the validate-behavior is configured for related object if (method_exists($this->aDiaporama, 'validate')) { if (!$this->aDiaporama->validate($validator)) { $failureMap->addAll($this->aDiaporama->getValidationFailures()); } } $retval = $validator->validate($this); if (count($retval) > 0) { $failureMap->addAll($retval); } if (null !== $this->collDiaporamaImageI18ns) { foreach ($this->collDiaporamaImageI18ns as $referrerFK) { if (method_exists($referrerFK, 'validate')) { if (!$referrerFK->validate($validator)) { $failureMap->addAll($referrerFK->getValidationFailures()); } } } } $this->alreadyInValidation = false; } $this->validationFailures = $failureMap; return (bool) (!(count($this->validationFailures) > 0)); }