* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ namespace PrestaShopBundle\Translation; use RuntimeException; /** * Normalizes domain names by removing dots */ class DomainNormalizer { /** * @param string $domain Domain name * * @return string * * @throws RuntimeException */ public function normalize($domain) { // 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; } }