Skip to content

Commit 56c5e9b

Browse files
AsifNawaz-cnicKaiSchwarz-cnic
authored andcommitted
fix(CommandFormatter.php): enhance priority handling for command properties and contact fields
1 parent 3762b39 commit 56c5e9b

File tree

1 file changed

+48
-26
lines changed

1 file changed

+48
-26
lines changed

src/CommandFormatter.php

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class CommandFormatter
1212
*/
1313
public static function getSortedCommand(array $command): array
1414
{
15-
$priority = self::getPriorityArray();
15+
$priority = self::getPropertiesPriority();
1616

1717
// Sort the command array based on priority
1818
uksort($command, function ($a, $b) use ($priority) {
@@ -69,46 +69,68 @@ public static function formatCommand(array $command): string
6969
}
7070

7171
/**
72-
* Get the priority array with regex patterns
72+
* Assign the priority of each key in the command array based on the key pattern
7373
*
74-
* @return array<string,int> The priority array
74+
* @return array<string,mixed>
7575
*/
76-
private static function getPriorityArray(): array
76+
private static function getPropertiesContactFieldsWithPriority(): array
7777
{
78-
$priority = [
78+
$keyProperties = [
7979
"COMMAND" => 1,
80-
"/^(DOMAIN|DNSZONE|NAMESERVER|ZONE|SUBUSER)[0-9]*$/" => 2,
81-
"/^(PERIOD|ACTION|AUTH|TARGET|X-FEE-COMMAND|RENEWALMODE|LIMIT|WIDE)$/" => 3,
82-
"/^(TRANSFERLOCK|DNSSEC0|X-FEE-AMOUNT|LOG|TYPE|OBJECT|INACTIVE|OBJECTID|OBJECTCLASS|ORDER|ORDERBY|CURRENCYFROM|CURRENCYTO)$/" => 4,
80+
"/^(DOMAIN|DNSZONE|NAMESERVER|ZONE|SUBUSER)[0-9]*$/i" => 2,
81+
"/^(PERIOD|ACTION|AUTH|TARGET|X-FEE-COMMAND|RENEWALMODE|LIMIT|WIDE)$/i" => 3,
82+
"/^(NS_LIST|TRANSFERLOCK|DNSSEC0|X-FEE-AMOUNT|LOG|TYPE|OBJECT|INACTIVE|OBJECTID|OBJECTCLASS|ORDER|ORDERBY|CURRENCYFROM|CURRENCYTO)$/i" => 4,
8383
];
8484

8585
$contactTypes = [
86-
"OWNERCONTACT" => 5,
87-
"ADMINCONTACT" => 6,
88-
"TECHCONTACT" => 7,
89-
"BILLINGCONTACT" => 8
86+
"OWNERCONTACT|REGISTRANT" => 5,
87+
"ADMINCONTACT|TECHNICAL" => 6,
88+
"TECHCONTACT|BILLING" => 7,
89+
"BILLINGCONTACT|ADMIN" => 8,
9090
];
9191
$contactFields = [
9292
"FIRSTNAME" => 1,
93-
"LASTNAME" => 2,
94-
"ORGANIZATION" => 3,
95-
"STREET" => 4,
96-
"ZIP" => 5,
97-
"CITY" => 6,
98-
"STATE" => 7,
99-
"COUNTRY" => 8,
100-
"PHONE" => 9,
101-
"EMAIL" => 10,
102-
"CONTACT" => 11
93+
"MIDDLENAME" => 2,
94+
"LASTNAME" => 3,
95+
"ORGANIZATION" => 4,
96+
"STREET" => 5,
97+
"ZIP" => 6,
98+
"CITY" => 7,
99+
"STATE" => 8,
100+
"COUNTRY" => 9,
101+
"PHONE|PHONENUMBER" => 10,
102+
"EMAIL" => 11,
103+
"CONTACT" => 12,
104+
"LEGALFORM" => 13,
105+
"IDENTIFICACION" => 14,
106+
"TIPO-IDENTIFICACION" => 15,
107+
];
108+
109+
return [
110+
"properties" => $keyProperties,
111+
"contact" => [
112+
"types" => $contactTypes,
113+
"fields" => $contactFields
114+
]
103115
];
116+
}
117+
118+
/**
119+
* Generate the priority array with properties dynamically including contact fields and their priority
120+
*
121+
* @return array<string,int> The priority array
122+
*/
123+
private static function getPropertiesPriority(): array
124+
{
125+
$propertiesWithPriority = self::getPropertiesContactFieldsWithPriority();
104126

105-
foreach ($contactTypes as $type => $typePriority) {
106-
foreach ($contactFields as $field => $fieldPriority) {
107-
$priority["/^{$type}[0-9]+{$field}$/"] = ($typePriority * 10) + $fieldPriority;
127+
foreach ($propertiesWithPriority["contact"]["types"] as $typePattern => $typePriority) {
128+
foreach ($propertiesWithPriority["contact"]["fields"] as $fieldPattern => $fieldPriority) {
129+
$propertiesWithPriority["properties"]["/^({$typePattern})[_0-9]*({$fieldPattern}[0-9]*)$/i"] = ($typePriority * 100) + $fieldPriority;
108130
}
109131
}
110132

111-
return $priority;
133+
return $propertiesWithPriority["properties"];
112134
}
113135

114136
/**

0 commit comments

Comments
 (0)