removeKnownPrefix($input); if ($identifierType === DomainIdentifier::QR_PAYLOAD || $identifierType === DomainIdentifier::QR_CODE) { return trim($payload); } if ($identifierType !== null && in_array($identifierType, self::NUMERIC_TYPES, true)) { $allowed = in_array($identifierType, [DomainIdentifier::ISBN10, DomainIdentifier::ISSN], true) ? '/[^0-9X]/' : '/\D/'; return preg_replace($allowed, '', strtoupper($payload)) ?? ''; } $compact = strtoupper(preg_replace('/[\s-]+/', '', $payload) ?? $payload); if (preg_match('/^[0-9X]+$/', $compact) === 1) { return $compact; } if ($identifierType !== null && in_array($identifierType, [ DomainIdentifier::ASIN, DomainIdentifier::MPN, DomainIdentifier::SKU, DomainIdentifier::MANUFACTURER_CODE, DomainIdentifier::INTERNAL_CODE, ], true)) { return strtoupper(trim($payload)); } return trim($payload); } private function removeKnownPrefix(string $value): string { $prefixes = implode('|', [ 'ISBN(?:10|13)?', 'EAN(?:8|13)?', 'UPC(?:-?[AE])?', 'GTIN', 'ISSN', 'ISMN', 'ASIN', 'JAN', 'MPN', 'SKU', 'MANUFACTURER CODE', 'BARCODE', 'QR(?:CODE| PAYLOAD| CODE)?', 'INTERNAL CODE', 'AIC(?:6|9)?', 'ATC', ]); return preg_replace('/^(?:' . $prefixes . ')\s*:\s*/i', '', $value) ?? $value; } }