public function buildMethodArgumentsValidatorConjunctions($className, $methodName, array $methodParameters = null, array $methodValidateAnnotations = null)
{
$validatorConjunctions = [];
if ($methodParameters === null) {
$methodParameters = $this->reflectionService->getMethodParameters($className, $methodName);
}
if (count($methodParameters) === 0) {
return $validatorConjunctions;
}
foreach ($methodParameters as $parameterName => $methodParameter) {
$validatorConjunction = $this->createValidator(ConjunctionValidator::class);
if (!array_key_exists('type', $methodParameter)) {
throw new Exception\InvalidTypeHintException('Missing type information, probably no @param annotation for parameter "$' . $parameterName . '" in ' . $className . '->' . $methodName . '()', 1281962564);
}
if (strpos($methodParameter['type'], '\\') === false) {
$typeValidator = $this->createValidator($methodParameter['type']);
} else {
$typeValidator = null;
}
if ($typeValidator !== null) {
$validatorConjunction->addValidator($typeValidator);
}
$validatorConjunctions[$parameterName] = $validatorConjunction;
}
if ($methodValidateAnnotations === null) {
$validateAnnotations = $this->reflectionService->getMethodAnnotations($className, $methodName, Flow\Validate::class);
$methodValidateAnnotations = array_map(function ($validateAnnotation) {
return ['type' => $validateAnnotation->type, 'options' => $validateAnnotation->options, 'argumentName' => $validateAnnotation->argumentName];
}, $validateAnnotations);
}
foreach ($methodValidateAnnotations as $annotationParameters) {
$newValidator = $this->createValidator($annotationParameters['type'], $annotationParameters['options']);
if ($newValidator === null) {
throw new Exception\NoSuchValidatorException('Invalid validate annotation in ' . $className . '->' . $methodName . '(): Could not resolve class name for validator "' . $annotationParameters['type'] . '".', 1239853109);
}
if (isset($validatorConjunctions[$annotationParameters['argumentName']])) {
$validatorConjunctions[$annotationParameters['argumentName']]->addValidator($newValidator);
} elseif (strpos($annotationParameters['argumentName'], '.') !== false) {
$objectPath = explode('.', $annotationParameters['argumentName']);
$argumentName = array_shift($objectPath);
$validatorConjunctions[$argumentName]->addValidator($this->buildSubObjectValidator($objectPath, $newValidator));
} else {
throw new Exception\InvalidValidationConfigurationException('Invalid validate annotation in ' . $className . '->' . $methodName . '(): Validator specified for argument name "' . $annotationParameters['argumentName'] . '", but this argument does not exist.', 1253172726);
}
}
return $validatorConjunctions;
}