Example #1
0
 /**
  * Validates the object and all objects related to this table.
  *
  * @see        getValidationFailures()
  * @param      ValidatorInterface|null $validator A Validator class instance
  * @return     boolean Whether all objects pass validation.
  */
 public function validate(ValidatorInterface $validator = null)
 {
     if (null === $validator) {
         $validator = new RecursiveValidator(new ExecutionContextFactory(new IdentityTranslator()), new LazyLoadingMetadataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory());
     }
     $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->aUser, 'validate')) {
             if (!$this->aUser->validate($validator)) {
                 $failureMap->addAll($this->aUser->getValidationFailures());
             }
         }
         $retval = $validator->validate($this);
         if (count($retval) > 0) {
             $failureMap->addAll($retval);
         }
         if (null !== $this->collArtistLyrics) {
             foreach ($this->collArtistLyrics as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collLyricLanguages) {
             foreach ($this->collLyricLanguages as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collLyricTranslations) {
             foreach ($this->collLyricTranslations as $referrerFK) {
                 if (method_exists($referrerFK, 'validate')) {
                     if (!$referrerFK->validate($validator)) {
                         $failureMap->addAll($referrerFK->getValidationFailures());
                     }
                 }
             }
         }
         if (null !== $this->collLyricVotes) {
             foreach ($this->collLyricVotes 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));
 }