-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathWorkerConfig.php
More file actions
54 lines (43 loc) · 1.31 KB
/
WorkerConfig.php
File metadata and controls
54 lines (43 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\PreviewGenerator\Model;
final class WorkerConfig implements \JsonSerializable {
private const WORKER_INDEX_KEY = 'workerIndex';
private const WORKER_COUNT_KEY = 'workerCount';
public function __construct(
private readonly int $workerIndex,
private readonly int $workerCount,
) {
}
/**
* @throws \InvalidArgumentException If the given JSON data is not valid
*/
public static function fromJson(array $data): self {
$workerIndex = $data[self::WORKER_INDEX_KEY] ?? null;
if (!is_int($workerIndex)) {
throw new \InvalidArgumentException('Invalid worker data: Missing worker index');
}
$workerCount = $data[self::WORKER_COUNT_KEY] ?? null;
if (!is_int($workerCount)) {
throw new \InvalidArgumentException('Invalid worker data: Missing worker count');
}
return new self($workerIndex, $workerCount);
}
public function getWorkerIndex(): int {
return $this->workerIndex;
}
public function getWorkerCount(): int {
return $this->workerCount;
}
#[\ReturnTypeWillChange]
public function jsonSerialize() {
return [
self::WORKER_INDEX_KEY => $this->workerIndex,
self::WORKER_COUNT_KEY => $this->workerCount,
];
}
}