From 9e44fcac499e30db187c599cd4a2195570e40c2a Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Thu, 27 Jul 2023 19:24:16 +0200 Subject: [PATCH] Allow BNE IDs starting with XX --- src/enums/MDNodaRepository.php | 20 +++++++++++++++++++- tests/MDNodaRepositoryTest.php | 4 +++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/enums/MDNodaRepository.php b/src/enums/MDNodaRepository.php index 97a05b9..45bf5a7 100644 --- a/src/enums/MDNodaRepository.php +++ b/src/enums/MDNodaRepository.php @@ -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/']), diff --git a/tests/MDNodaRepositoryTest.php b/tests/MDNodaRepositoryTest.php index fe36ce9..9c00b14 100644 --- a/tests/MDNodaRepositoryTest.php +++ b/tests/MDNodaRepositoryTest.php @@ -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")); + } }