Skip to content

Commit 8af2d1d

Browse files
committed
feat(policy): add collect_metadata definition provider
Signed-off-by: Vitor Mattos <[email protected]>
1 parent 57475b9 commit 8af2d1d

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Libresign\Service\Policy\Provider\CollectMetadata;
10+
11+
use OCA\Libresign\Service\Policy\Contract\IPolicyDefinition;
12+
use OCA\Libresign\Service\Policy\Contract\IPolicyDefinitionProvider;
13+
use OCA\Libresign\Service\Policy\Model\PolicySpec;
14+
15+
final class CollectMetadataPolicy implements IPolicyDefinitionProvider {
16+
public const KEY = 'collect_metadata';
17+
public const SYSTEM_APP_CONFIG_KEY = 'collect_metadata';
18+
19+
#[\Override]
20+
public function keys(): array {
21+
return [
22+
self::KEY,
23+
];
24+
}
25+
26+
#[\Override]
27+
public function get(string|\BackedEnum $policyKey): IPolicyDefinition {
28+
return match ($this->normalizePolicyKey($policyKey)) {
29+
self::KEY => new PolicySpec(
30+
key: self::KEY,
31+
defaultSystemValue: false,
32+
allowedValues: [
33+
false,
34+
true,
35+
],
36+
normalizer: static fn (mixed $rawValue): bool => filter_var($rawValue, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? false,
37+
appConfigKey: self::SYSTEM_APP_CONFIG_KEY,
38+
),
39+
default => throw new \InvalidArgumentException('Unknown policy key: ' . $this->normalizePolicyKey($policyKey)),
40+
};
41+
}
42+
43+
private function normalizePolicyKey(string|\BackedEnum $policyKey): string {
44+
if ($policyKey instanceof \BackedEnum) {
45+
return (string)$policyKey->value;
46+
}
47+
48+
return $policyKey;
49+
}
50+
}

0 commit comments

Comments
 (0)