Files
Sebastian e04957de5e refactor: comments
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-06-28 18:07:13 -04:00

72 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* 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<string,mixed> $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;
}
}