errors = []; foreach (array_keys($this->getValidationRegistry()->getValidators($schema)) as $field) { $mappedField = $this->getConfigurationMapper()->map($field); if (!$mappedField) { continue; } foreach ($this->getValidationFactory()->createFormValidators($schema, $field) as $validators) { $this->validateMappedField($validators, $data, $mappedField); } } if (!empty($this->errors)) { $errors = $this->errors; $this->errors = []; throw new InvalidArgumentException(implode($errors, PHP_EOL)); } } private function validateMappedField(array $validators, array $data, string $mappedField): void { foreach ($validators as $validator) { if ($validator->evaluate($data[$mappedField] ?? null)) { continue; } $this->errors[] = sprintf('"%s": %s', $mappedField, $validator->getMessage()); } } private function getConfigurationMapper(): LtiProviderFieldsMapper { /** @noinspection PhpIncompatibleReturnTypeInspection */ return $this->getServiceLocator()->get(LtiProviderFieldsMapper::class); } private function getValidationFactory(): ValidatorsFactory { /** @noinspection PhpIncompatibleReturnTypeInspection */ return $this->getServiceLocator()->get(ValidatorsFactory::class); } private function getValidationRegistry(): ValidationRegistry { /** @noinspection PhpIncompatibleReturnTypeInspection */ return $this->getServiceLocator()->get(ValidationRegistry::class); } }