* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ declare(strict_types=1); namespace PrestaShop\PrestaShop\Core\Translation\Storage\Normalizer; use RuntimeException; /** * Normalizes domain names by removing dots */ class DomainNormalizer { /** * @param string $domain Domain name * * @return string * * @throws RuntimeException */ public function normalize(string $domain): string { // remove up to two dots from the domain name // (because legacy domain translations CAN have dots in the third part) $normalizedDomain = preg_replace('/\./', '', $domain, 2); if ($normalizedDomain === null) { throw new RuntimeException(sprintf('An error occurred while normalizing domain "%s"', $domain)); } return $normalizedDomain; } }