-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathRulesService.php
More file actions
70 lines (61 loc) · 1.46 KB
/
RulesService.php
File metadata and controls
70 lines (61 loc) · 1.46 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Service\Certificate;
use OCP\IL10N;
class RulesService {
private array $rules = [
'CN' => [
'required' => true,
'min' => 1,
'max' => 64,
],
'C' => [
'min' => 2,
'max' => 2,
],
'ST' => [
'min' => 1,
'max' => 128,
],
'L' => [
'min' => 1,
'max' => 128,
],
'O' => [
'min' => 1,
'max' => 64,
],
'OU' => [
'min' => 1,
'max' => 64,
],
];
public function __construct(
protected IL10N $l10n,
) {
}
public function getRule(string $fieldName): array {
if (!isset($this->rules[$fieldName]['helperText'])) {
$this->rules[$fieldName]['helperText'] = $this->getHelperText($fieldName);
if (empty($this->rules[$fieldName]['helperText'])) {
unset($this->rules[$fieldName]['helperText']);
}
}
return $this->rules[$fieldName];
}
public function getHelperText(string $fieldName): ?string {
return match ($fieldName) {
'CN' => $this->l10n->t('Common Name (CN)'),
'C' => $this->l10n->t('Two-letter ISO 3166 country code'),
'ST' => $this->l10n->t('Full name of states or provinces'),
'L' => $this->l10n->t('Name of a locality or place, such as a city, county, or other geographic region'),
'O' => $this->l10n->t('Name of an organization'),
'OU' => $this->l10n->t('Name of an organizational unit'),
default => null,
};
}
}