Skip to content

Commit dfa3f2e

Browse files
committed
fix: workaround to make compatible with different structures
todo: unify the key to be only 'identify' or only 'identifyMethods' Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 3570a66 commit dfa3f2e

1 file changed

Lines changed: 42 additions & 4 deletions

File tree

lib/Helper/ValidateHelper.php

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,14 +526,52 @@ private function validateSignerData(mixed $signer): void {
526526
}
527527

528528
private function validateSignerIdentifyMethods(array $signer): void {
529-
if (empty($signer['identify']) || !is_array($signer['identify'])) {
530-
// It's an api error, don't translate
529+
$normalizedMethods = $this->normalizeIdentifyMethods($signer);
530+
531+
foreach ($normalizedMethods as $method) {
532+
$this->validateIdentifyMethodForRequest($method['name'], $method['value']);
533+
}
534+
}
535+
536+
/**
537+
* @todo unify the key to be only 'identify' or only 'identifyMethods'
538+
*/
539+
private function normalizeIdentifyMethods(array $signer): array {
540+
$key = array_key_exists('identifyMethods', $signer) ? 'identifyMethods' : 'identify';
541+
542+
if (empty($signer[$key]) || !is_array($signer[$key])) {
531543
throw new LibresignException('No identify methods for signer');
532544
}
533545

534-
foreach ($signer['identify'] as $name => $identifyValue) {
535-
$this->validateIdentifyMethodForRequest($name, $identifyValue);
546+
$normalizedMethods = [];
547+
548+
foreach ($signer[$key] as $name => $data) {
549+
if ($key === 'identifyMethods') {
550+
$normalizedMethods[] = $this->normalizeIdentifyMethodsStructure($data);
551+
} else {
552+
$normalizedMethods[] = $this->normalizeIdentifyStructure($name, $data);
553+
}
554+
}
555+
556+
return $normalizedMethods;
557+
}
558+
559+
private function normalizeIdentifyMethodsStructure(mixed $data): array {
560+
if (!is_array($data) || !array_key_exists('method', $data) || !array_key_exists('value', $data)) {
561+
throw new LibresignException('Invalid identify method structure');
536562
}
563+
564+
return [
565+
'name' => $data['method'],
566+
'value' => $data['value'],
567+
];
568+
}
569+
570+
private function normalizeIdentifyStructure(string $name, mixed $value): array {
571+
return [
572+
'name' => $name,
573+
'value' => $value,
574+
];
537575
}
538576

539577
private function validateIdentifyMethodForRequest(string $name, string $identifyValue): void {

0 commit comments

Comments
 (0)