* SPDX-License-Identifier: AGPL-3.0-or-later */ namespace KTXM\PeopleManager\Import; use InvalidArgumentException; 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(); $options->supersede = (bool)($data['supersede'] ?? false); $options->counts = (bool)($data['counts'] ?? true); $options->errors = (int)($data['errors'] ?? self::ERROR_CONTINUE); if (!in_array($options->errors, [self::ERROR_CONTINUE, self::ERROR_FAIL], true)) { throw new InvalidArgumentException('Invalid errors option specified'); } return $options; } }