protected function isValid($value)
    {
        if ($value instanceof \Doctrine\ORM\PersistentCollection && !$value->isInitialized()) {
            return;
        } elseif ((is_object($value) && !TypeHandling::isCollectionType(get_class($value))) && !is_array($value)) {
            $this->addError('The given subject was not a collection.', 1317204797);
            return;
        } elseif (is_object($value) && $this->isValidatedAlready($value)) {
            return;
        }

        foreach ($value as $index => $collectionElement) {
            if (isset($this->options['elementValidator'])) {
                $collectionElementValidator = $this->validatorResolver->createValidator($this->options['elementValidator'], $this->options['elementValidatorOptions']);
            } elseif (isset($this->options['elementType'])) {
                if (isset($this->options['validationGroups'])) {
                    $collectionElementValidator = $this->validatorResolver->getBaseValidatorConjunction($this->options['elementType'], $this->options['validationGroups']);
                } else {
                    $collectionElementValidator = $this->validatorResolver->getBaseValidatorConjunction($this->options['elementType']);
                }
            } else {
                return;
            }
            if ($collectionElementValidator instanceof ObjectValidatorInterface) {
                $collectionElementValidator->setValidatedInstancesContainer($this->validatedInstancesContainer);
            }

            $this->result->forProperty($index)->merge($collectionElementValidator->validate($collectionElement));
        }
    }
protected function isValid($value)
    {
        if ($value instanceof \Doctrine\ORM\PersistentCollection && !$value->isInitialized()) {
            return;
        } elseif ((is_object($value) && !TypeHandling::isCollectionType(get_class($value))) && !is_array($value)) {
            $this->addError('The given subject was not a collection.', 1317204797);
            return;
        } elseif (is_object($value) && $this->isValidatedAlready($value)) {
            return;
        }

        foreach ($value as $index => $collectionElement) {
            if (isset($this->options['elementValidator'])) {
                $collectionElementValidator = $this->validatorResolver->createValidator($this->options['elementValidator'], $this->options['elementValidatorOptions']);
            } elseif (isset($this->options['elementType'])) {
                if (isset($this->options['validationGroups'])) {
                    $collectionElementValidator = $this->validatorResolver->getBaseValidatorConjunction($this->options['elementType'], $this->options['validationGroups']);
                } else {
                    $collectionElementValidator = $this->validatorResolver->getBaseValidatorConjunction($this->options['elementType']);
                }
            } else {
                return;
            }
            if ($collectionElementValidator instanceof ObjectValidatorInterface) {
                $collectionElementValidator->setValidatedInstancesContainer($this->validatedInstancesContainer);
            }

            $this->result->forProperty($index)->merge($collectionElementValidator->validate($collectionElement));
        }
    }
protected function isValid ( $ value ) { if ( $ value instanceof \ Doctrine \ ORM \ PersistentCollection && ! $ value -> isInitialized ( ) ) { return ; } elseif ( ( is_object ( $ value ) && ! TypeHandling :: isCollectionType ( get_class ( $ value ) ) ) && ! is_array ( $ value ) ) { $ this -> addError ( 'The given subject was not a collection.' , 1317204797 ) ; return ; } elseif ( is_object ( $ value ) && $ this -> isValidatedAlready ( $ value ) ) { return ; } foreach ( $ value as $ index => $ collectionElement ) { if ( isset ( $ this -> options [ 'elementValidator' ] ) ) { $ collectionElementValidator = $ this -> validatorResolver -> createValidator ( $ this -> options [ 'elementValidator' ] , $ this -> options [ 'elementValidatorOptions' ] ) ; } elseif ( isset ( $ this -> options [ 'elementType' ] ) ) { if ( isset ( $ this -> options [ 'validationGroups' ] ) ) { $ collectionElementValidator = $ this -> validatorResolver -> getBaseValidatorConjunction ( $ this -> options [ 'elementType' ] , $ this -> options [ 'validationGroups' ] ) ; } else { $ collectionElementValidator = $ this -> validatorResolver -> getBaseValidatorConjunction ( $ this -> options [ 'elementType' ] ) ; } } else { return ; } if ( $ collectionElementValidator instanceof ObjectValidatorInterface ) { $ collectionElementValidator -> setValidatedInstancesContainer ( $ this -> validatedInstancesContainer ) ; } $ this -> result -> forProperty ( $ index ) -> merge ( $ collectionElementValidator -> validate ( $ collectionElement ) ) ; } }
Checks for a collection and if needed validates the items in the collection.
This is done with the specified element validator or a validator based on
the given element type and validation group.

Either elementValidator or elementType must be given, otherwise validation
will be skipped.

@param mixed $value A collection to be validated
@return void
Checks for a collection and if needed validates the items in the collection . This is done with the specified element validator or a validator based on the given element type and validation group .