/** * If a URL is not punycoded, then it may be an IDNA URL, so it must be * converted to ASCII. Performs conversion and sets flag. * * @param string $part Host part * * @return string Host part, transformed if not punycoded */ protected function normalize($part) { $punycoded = strpos($part, 'xn--') !== false; if ($punycoded === false) { $part = $this->punycodeWrapper->encode($part); $this->isNormalized = true; } return strtolower($part); }
/** * Recursive method to build the array representation of the Public Suffix List. * * This method is based heavily on the code found in generateEffectiveTLDs.php * * @link https://github.com/usrflo/registered-domain-libs/blob/master/generateEffectiveTLDs.php * A copy of the Apache License, Version 2.0, is provided with this * distribution * * @param array $publicSuffixListArray Initially an empty array, this eventually * becomes the array representation of the Public Suffix List * @param array $ruleParts One line (rule) from the Public Suffix List * exploded on '.', or the remaining portion of that array during recursion */ public function buildArray(array &$publicSuffixListArray, array $ruleParts) { $isDomain = true; $part = array_pop($ruleParts); // Adheres to canonicalization rule from the "Formal Algorithm" section // of https://publicsuffix.org/list/ // "The domain and all rules must be canonicalized in the normal way // for hostnames - lower-case, Punycode (RFC 3492)." $punycode = new PunycodeWrapper(); $part = $punycode->encode($part); if (strpos($part, '!') === 0) { $part = substr($part, 1); $isDomain = false; } if (!isset($publicSuffixListArray[$part])) { if ($isDomain) { $publicSuffixListArray[$part] = array(); } else { $publicSuffixListArray[$part] = array('!' => ''); } } if ($isDomain && count($ruleParts) > 0) { $this->buildArray($publicSuffixListArray[$part], $ruleParts); } }