Allow BNE IDs starting with XX

This commit is contained in:
Joshua Ramon Enslin 2023-07-27 19:24:16 +02:00
parent f5673c69fd
commit 9e44fcac49
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
2 changed files with 22 additions and 2 deletions

View File

@ -62,6 +62,8 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
'edition humboldt digital' => self::editionhumboldtdigital,
'gnd' => self::gnd,
'GND' => self::gnd,
'http://d-nb.info/gnd' => self::gnd,
'http://d-nb.info/gnd/' => self::gnd,
'grobsystematik' => self::grobsystematik,
'iconclass' => self::iconclass,
'lcsh' => self::lcsh,
@ -85,6 +87,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
'ulan' => self::ulan,
'viaf' => self::viaf,
'wikidata' => self::wikidata,
'wikipedia' => self::wikipedia,
'Wikipedia' => self::wikipedia,
default => throw new MDpageParameterNotFromListException("Unknown noda repository: '" . $input . "'"),
};
@ -287,6 +290,21 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
}
/**
* Validates a BNE ID, returning a string or false. The BNE is basically equalivalent to the
* GND, just that the X character can be prepended to the number.
*
* @param string $id ID to validate.
* @param string[] $prefixes Prefixes to strip off.
*
* @return string|false
*/
private static function validateBneId(string $id, array $prefixes):string|false {
return self::validateGndId($id, $prefixes);
}
/**
* Validates a GND ID, returning a string or false.
*
@ -409,7 +427,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
self::allgemein => filter_var($id, FILTER_VALIDATE_URL),
self::aat => self::validateNumericId($id, ['https://vocab.getty.edu/page/aat/']),
self::ackerbau => self::validateNumericId($id, ['https://term.museum-digital.de/ackerbau/tag/']),
self::bne => self::validateNumericId($id, ['http://datos.bne.es/persona/']),
self::bne => self::validateGndId($id, ['http://datos.bne.es/persona/']),
self::bnf => self::validateNumericId(rtrim($id, 't'), ["https://catalogue.bnf.fr/ark:/12148/cb"]), // cb11960399t is a valid entry, too (general)
self::cona => self::validateNumericId($id, ['https://vocab.getty.edu/page/cona/']),
self::editionhumboldtdigital => self::validateGndId($id, ['https://edition-humboldt.de/register/personen/detail.xql?normid=http://d-nb.info/gnd/']),

View File

@ -39,10 +39,12 @@ final class MDNodaRepositoryTest extends TestCase {
self::assertNotFalse(MDNodaRepository::loc->validateId("http://id.loc.gov/authorities/names/n2022014604"));
self::assertNotFalse(MDNodaRepository::loc->validateId("n2022014604"));
self::assertNotFalse(MDNodaRepository::lcsh->validateId("https://id.loc.gov/authorities/names/sh2022014604"));
self::assertNotFalse(MDNodaRepository::lcsh->validateId("http://id.loc.gov/authorities/names/sh2022014604"));
self::assertNotFalse(MDNodaRepository::lcsh->validateId("sh2022014604"));
self::assertNotFalse(MDNodaRepository::bne->validateId("http://datos.bne.es/persona/XX5034943"));
self::assertNotFalse(MDNodaRepository::bne->validateId("XX5034943"));
}
}