Made key and name attributes optional in register-group-instance TDF elements

Also removed the attribute from all instances of the element, where it wasn't necessary.
This commit is contained in:
Nav
2024-08-13 19:54:05 +01:00
parent 7cf5afde2d
commit f1c82ecd28
265 changed files with 8717 additions and 8742 deletions

View File

@@ -166,18 +166,9 @@ class ValidationService
if (empty($propertyGroup->key)) {
$failures[] = 'Missing key';
}
if (!mb_check_encoding((string) $propertyGroup->key, 'ASCII')) {
$failures[] = 'Key contains non ASCII characters';
}
if (str_contains((string) $propertyGroup->key, ' ')) {
$failures[] = 'Key contains at least one white character';
}
if (str_contains((string) $propertyGroup->key, '.')) {
$failures[] = 'Key contains at least one period (".") character';
} else {
$failures = array_merge($failures, $this->validateKey($propertyGroup->key));
}
if (empty($propertyGroup->subPropertyGroups) && empty($propertyGroup->properties)) {
@@ -219,18 +210,9 @@ class ValidationService
if (empty($property->key)) {
$failures[] = 'Missing key';
}
if (!mb_check_encoding((string) $property->key, 'ASCII')) {
$failures[] = 'Key contains non ASCII characters';
}
if (str_contains((string) $property->key, ' ')) {
$failures[] = 'Key contains at least white space character';
}
if (str_contains((string) $property->key, '.')) {
$failures[] = 'Key contains at least one period (".") character';
} else {
$failures = array_merge($failures, $this->validateKey($property->key));
}
if ($property->value === null) {
@@ -312,14 +294,9 @@ class ValidationService
if (empty($segment->key)) {
$failures[] = 'Missing key';
}
if (!preg_match('/^[a-z_]+$/',$segment->key)) {
$failures[] = 'Key must contain only lowercase letters';
}
if (!mb_check_encoding((string) $segment->key, 'ASCII')) {
$failures[] = 'Key must contain only ASCII characters';
} else {
$failures = array_merge($failures, $this->validateKey($segment->key));
}
if (empty($segment->name)) {
@@ -445,18 +422,9 @@ class ValidationService
if (empty($registerGroup->key)) {
$failures[] = 'Missing key';
}
if (!mb_check_encoding((string) $registerGroup->key, 'ASCII')) {
$failures[] = 'Key contains non ASCII characters';
}
if (str_contains((string) $registerGroup->key, ' ')) {
$failures[] = 'Key contains at least one white character';
}
if (str_contains((string) $registerGroup->key, '.')) {
$failures[] = 'Key contains at least one period (".") character';
} else {
$failures = array_merge($failures, $this->validateKey($registerGroup->key));
}
if (empty($registerGroup->name)) {
@@ -534,18 +502,9 @@ class ValidationService
if (empty($registerGroupReference->key)) {
$failures[] = 'Missing key';
}
if (!mb_check_encoding((string) $registerGroupReference->key, 'ASCII')) {
$failures[] = 'Key contains non ASCII characters';
}
if (str_contains((string) $registerGroupReference->key, ' ')) {
$failures[] = 'Key contains at least one period space';
}
if (str_contains((string) $registerGroupReference->key, '.')) {
$failures[] = 'Key contains at least one period (".") character';
} else {
$failures = array_merge($failures, $this->validateKey($registerGroupReference->key));
}
if (empty($registerGroupReference->registerGroupKey)) {
@@ -581,18 +540,9 @@ class ValidationService
if (empty($register->key)) {
$failures[] = 'Missing key';
}
if (!mb_check_encoding((string) $register->key, 'ASCII')) {
$failures[] = 'Key contains non ASCII character';
}
if (str_contains((string) $register->key, ' ')) {
$failures[] = 'Key contains at least white space character';
}
if (str_contains((string) $register->key, '.')) {
$failures[] = 'Key contains at least one period (".") character';
} else {
$failures = array_merge($failures, $this->validateKey($register->key));
}
if (empty($register->name)) {
@@ -750,30 +700,14 @@ class ValidationService
): array {
$failures = [];
if (empty($registerGroupInstance->key)) {
$failures[] = 'Missing key';
}
if (!mb_check_encoding((string) $registerGroupInstance->key, 'ASCII')) {
$failures[] = 'Key contains non ASCII characters';
}
if (str_contains((string) $registerGroupInstance->key, ' ')) {
$failures[] = 'Key contains at least one period space';
}
if (str_contains((string) $registerGroupInstance->key, '.')) {
$failures[] = 'Key contains at least one period (".") character';
if (!empty($registerGroupInstance->key)) {
$failures = array_merge($failures, $this->validateKey($registerGroupInstance->key));
}
if (empty($registerGroupInstance->registerGroupKey)) {
$failures[] = 'Missing register group key';
}
if (empty($registerGroupInstance->name)) {
$failures[] = 'Missing name';
}
if ($registerGroupInstance->offset === null) {
$failures[] = 'Missing offset';
@@ -978,4 +912,31 @@ class ValidationService
$failures
);
}
protected function validateKey(string $key): array
{
$failures = [];
if (!mb_check_encoding($key, 'ASCII')) {
$failures[] = 'Key contains non ASCII characters';
}
if (strtolower($key) !== $key) {
$failures[] = 'Key must contain only lowercase characters';
}
if (str_contains($key, ' ')) {
$failures[] = 'Key contains at least one whitespace';
}
if (str_contains($key, '.')) {
$failures[] = 'Key contains at least one period (".") character';
}
return array_map(
fn (string $failure): string => 'Key validation failure for key "' . $key
. '": ' . $failure,
$failures
);
}
}

View File

@@ -162,8 +162,14 @@ class ToXmlService
DOMDocument $document
): DOMElement {
$element = $document->createElement('register-group-instance');
$element->setAttribute('key', $registerGroupInstance->key);
$element->setAttribute('name', $registerGroupInstance->name);
if (!empty($registerGroupInstance->key)) {
$element->setAttribute('key', $registerGroupInstance->key);
}
if (!empty($registerGroupInstance->name)) {
$element->setAttribute('name', $registerGroupInstance->name);
}
if (!empty($registerGroupInstance->description)) {
$element->setAttribute('description', $registerGroupInstance->description);