b7e12621cd
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
67 lines
1.9 KiB
PHP
67 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace KTXM\ChronoManager\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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|