*/ private array $sources = []; /** * Register an import source. * * @param FormImportSourceInterface $source * @return void */ public function register(FormImportSourceInterface $source): void { $this->sources[] = $source; } /** * @return array */ public function getAll(): array { return $this->sources; } /** * Find the first registered source that matches the payload. * * @param array $importData * @return FormImportSourceInterface|null */ public function findMatching(array $importData): ?FormImportSourceInterface { foreach ($this->sources as $source) { if ($source->matches($importData)) { return $source; } } return null; } /** * Normalize a payload using the first matching registered source. * * @param array $importData * @return array * @throws InvalidArgumentException */ public function normalize(array $importData): array { $source = $this->findMatching($importData); if ($source === null) { throw new InvalidArgumentException( BackendStrings::getExceptionStrings()['unsupported_import_format'] ); } return $source->normalize($importData); } }