protected function buildBaseValidatorConjunction($indexKey, $targetClassName, array $validationGroups)
{
$conjunctionValidator = new ConjunctionValidator();
$this->baseValidatorConjunctions[$indexKey] = $conjunctionValidator;
if (!TypeHandling::isSimpleType($targetClassName) && class_exists($targetClassName)) {
// Model based validator
$classSchema = $this->reflectionService->getClassSchema($targetClassName);
if ($classSchema !== null && $classSchema->isAggregateRoot()) {
$objectValidator = new AggregateBoundaryValidator(array());
} else {
$objectValidator = new GenericObjectValidator([]);
}
$conjunctionValidator->addValidator($objectValidator);
foreach ($this->reflectionService->getClassPropertyNames($targetClassName) as $classPropertyName) {
$classPropertyTagsValues = $this->reflectionService->getPropertyTagsValues($targetClassName, $classPropertyName);
if (!isset($classPropertyTagsValues['var'])) {
throw new \InvalidArgumentException(sprintf('There is no @var annotation for property "%s" in class "%s".', $classPropertyName, $targetClassName), 1363778104);
}
try {
$parsedType = TypeHandling::parseType(trim(implode('', $classPropertyTagsValues['var']), ' \\'));
} catch (InvalidTypeException $exception) {
throw new \InvalidArgumentException(sprintf(' @var annotation of ' . $exception->getMessage(), 'class "' . $targetClassName . '", property "' . $classPropertyName . '"'), 1315564744, $exception);
}
if ($this->reflectionService->isPropertyAnnotatedWith($targetClassName, $classPropertyName, Flow\IgnoreValidation::class)) {
continue;
}
$propertyTargetClassName = $parsedType['type'];
if (TypeHandling::isCollectionType($propertyTargetClassName) === true) {
$collectionValidator = $this->createValidator(Validator\CollectionValidator::class, ['elementType' => $parsedType['elementType'], 'validationGroups' => $validationGroups]);
$objectValidator->addPropertyValidator($classPropertyName, $collectionValidator);
} elseif (!TypeHandling::isSimpleType($propertyTargetClassName) && $this->objectManager->isRegistered($propertyTargetClassName) && $this->objectManager->getScope($propertyTargetClassName) === Configuration::SCOPE_PROTOTYPE) {
$validatorForProperty = $this->getBaseValidatorConjunction($propertyTargetClassName, $validationGroups);
if (count($validatorForProperty) > 0) {
$objectValidator->addPropertyValidator($classPropertyName, $validatorForProperty);
}
}
$validateAnnotations = $this->reflectionService->getPropertyAnnotations($targetClassName, $classPropertyName, Flow\Validate::class);
foreach ($validateAnnotations as $validateAnnotation) {
if (count(array_intersect($validateAnnotation->validationGroups, $validationGroups)) === 0) {
// In this case, the validation groups for the property do not match current validation context
continue;
}
$newValidator = $this->createValidator($validateAnnotation->type, $validateAnnotation->options);
if ($newValidator === null) {
throw new Exception\NoSuchValidatorException('Invalid validate annotation in ' . $targetClassName . '::' . $classPropertyName . ': Could not resolve class name for validator "' . $validateAnnotation->type . '".', 1241098027);
}
$objectValidator->addPropertyValidator($classPropertyName, $newValidator);
}
}
if (count($objectValidator->getPropertyValidators()) === 0) {
$conjunctionValidator->removeValidator($objectValidator);
}
}
$this->addCustomValidators($targetClassName, $conjunctionValidator);
}