Exemple #1
0
 /**
  * Converts any normalized part back to IDNA. Performs conversion and
  * resets flag.
  *
  * @param string $part Host part
  *
  * @return string Denormalized host part
  */
 protected function denormalize($part)
 {
     if ($this->isNormalized === true) {
         $part = $this->punycodeWrapper->decode($part);
         $this->isNormalized = false;
     }
     return $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);
     }
 }