getExpectedDomains($identifierType, $normalizedValue); if ($this->usesGs1Prefix($identifierType) && preg_match('/^\d{3}/', $normalizedValue, $matches) === 1) { $gs1Prefix = $matches[0]; [$countryPrefix, $prefixNote] = $this->resolveGs1Prefix((int) $gs1Prefix); if ($prefixNote !== null) { $notes[] = $prefixNote; } } if ($identifierType === DomainIdentifier::ISBN13 && str_starts_with($normalizedValue, '978')) { $countryPrefix = $this->resolveIsbnRegistrationGroup($normalizedValue); $notes[] = '978 is the GS1 Bookland prefix.'; } if ($identifierType === DomainIdentifier::ISBN13 && str_starts_with($normalizedValue, '979')) { $notes[] = '979 is a GS1 Bookland prefix also used by music publications.'; } return [ 'country_prefix' => $countryPrefix, 'gs1_prefix' => $gs1Prefix, 'expected_domains' => $expectedDomains, 'notes' => $notes, ]; } private function getExpectedDomains(string $identifierType, string $value): array { if ($identifierType === DomainIdentifier::ISBN13 && str_starts_with($value, '979')) { return [DomainRegistry::BOOKS, DomainRegistry::MUSIC]; } $map = [ DomainIdentifier::ISBN10 => [DomainRegistry::BOOKS], DomainIdentifier::ISBN13 => [DomainRegistry::BOOKS], DomainIdentifier::ISSN => [DomainRegistry::BOOKS], DomainIdentifier::ISMN => [DomainRegistry::MUSIC], DomainIdentifier::ASIN => [DomainRegistry::GENERIC_PRODUCTS], DomainIdentifier::AIC6 => [DomainRegistry::MEDICAL], DomainIdentifier::AIC9 => [DomainRegistry::MEDICAL], DomainIdentifier::AIC => [DomainRegistry::MEDICAL], DomainIdentifier::ATC => [DomainRegistry::MEDICAL], ]; return $map[$identifierType] ?? [DomainRegistry::GENERIC_PRODUCTS]; } private function usesGs1Prefix(string $identifierType): bool { return in_array($identifierType, [ DomainIdentifier::ISBN13, DomainIdentifier::EAN13, DomainIdentifier::UPC_A, DomainIdentifier::GTIN, DomainIdentifier::ISMN, DomainIdentifier::JAN, ], true); } private function resolveGs1Prefix(int $prefix): array { if ($prefix >= 0 && $prefix <= 19) { return ['United States / Canada', 'GS1 prefix assigned to United States / Canada.']; } if ($prefix >= 400 && $prefix <= 440) { return ['Germany', 'GS1 prefix assigned to Germany.']; } if ($prefix >= 450 && $prefix <= 459 || $prefix >= 490 && $prefix <= 499) { return ['Japan', 'GS1 prefix assigned to Japan.']; } if ($prefix >= 500 && $prefix <= 509) { return ['United Kingdom', 'GS1 prefix assigned to the United Kingdom.']; } if ($prefix >= 800 && $prefix <= 839) { return ['Italy', 'GS1 prefix assigned to Italy.']; } if ($prefix === 978 || $prefix === 979) { return ['Bookland', 'GS1 prefix assigned to Bookland.']; } return [null, 'Unknown prefix.']; } private function resolveIsbnRegistrationGroup(string $value): string { $group = substr($value, 3, 2); if ($group === '88') { return 'Italy'; } if ($value[3] === '3') { return 'Germany'; } if (in_array($value[3], ['0', '1'], true)) { return 'English language area'; } return 'Bookland'; } }