* SPDX-License-Identifier: AGPL-3.0-or-later */ namespace KTXM\PeopleManager\Import; use InvalidArgumentException; /** * Configuration for a contact import run. */ final class ImportOptions { public const ERROR_CONTINUE = 0; public const ERROR_FAIL = 1; public const ERROR_OPTIONS = [self::ERROR_CONTINUE, self::ERROR_FAIL]; /** Overwrite an existing entity when the same UID is already present. */ private bool $supersede = false; /** Emit an ImportCountEvent (discovered total) before the object stream. */ private bool $counts = true; /** How to handle per-object errors. */ private int $errors = self::ERROR_CONTINUE; public function getSupersede(): bool { return $this->supersede; } public function setSupersede(bool $value): void { $this->supersede = $value; } public function getCounts(): bool { return $this->counts; } public function setCounts(bool $value): void { $this->counts = $value; } public function getErrors(): int { return $this->errors; } public function setErrors(int $value): void { if (!in_array($value, self::ERROR_OPTIONS, true)) { throw new InvalidArgumentException('Invalid errors option specified'); } $this->errors = $value; } /** * Build options from the raw `options` array carried in the request. * * @param array $data */ public static function fromArray(array $data): self { $options = new self(); if (isset($data['supersede'])) { $options->setSupersede((bool)$data['supersede']); } if (isset($data['counts'])) { $options->setCounts((bool)$data['counts']); } if (isset($data['errors'])) { $options->setErrors((int)$data['errors']); } return $options; } }