Пример #1
0
 /**
  * Validate Host data before insertion into a URL host component
  *
  * @param mixed $data the data to insert
  *
  * @return array
  *
  * @throws RuntimeException If the added is invalid
  */
 protected function validate($data)
 {
     $data = $this->validateSegment($data);
     if (!$data) {
         return $data;
     }
     $this->saveInternalEncoding();
     if (!$this->isValidHostLength($data)) {
         $this->restoreInternalEncoding();
         throw new RuntimeException('Invalid hostname, check its length');
     } elseif (!$this->isValidHostPattern($data)) {
         $this->restoreInternalEncoding();
         throw new RuntimeException('Invalid host label, check its content');
     } elseif (!$this->isValidHostLabels($data)) {
         $this->restoreInternalEncoding();
         throw new RuntimeException('Invalid host label counts, check its count');
     }
     $data = $this->sanitizeValue($data);
     $data = explode($this->delimiter, $this->punycode->decode(implode($this->delimiter, $data)));
     $this->restoreInternalEncoding();
     return $data;
 }
Пример #2
0
 /**
  * Converts domain part of the address to punycode if needed.
  *
  * @param string $address The address that should be normalized.
  * @return string
  */
 private static function normalizeAddress($address)
 {
     $chunks = explode('@', $address);
     if (count($chunks) < 2) {
         // The address has no "@" character thus it's not a real email
         // address and should not be normalized at all.
         return $address;
     }
     $punycode = new Punycode();
     // Domain part should be converted to punycode to play nice with IDN.
     $domain = $punycode->encode(array_pop($chunks));
     // Local part should be left as is.
     $local_part = implode('@', $chunks);
     return $local_part . '@' . $domain;
 }
Пример #3
0
 /**
  * Decode an internationalized domain name
  *
  * @param string $strDomain The domain name
  *
  * @return string The decoded domain name
  */
 public static function decode($strDomain)
 {
     $objPunycode = new Punycode();
     return $objPunycode->decode($strDomain);
 }
Пример #4
0
 /** Возвратить адрес как строку */
 public function asString($absolute = false)
 {
     $url = '/';
     if ($absolute) {
         $puny = new Punycode();
         $url = $this->getScheme() . '://' . $puny->encode($this->getHost()) . '/';
     }
     if ($a = $this->getArguments()) {
         foreach ($this->getArguments() as $str) {
             $url .= urlencode($str) . '/';
         }
     }
     $url .= $this->buildParams();
     if ($fn = $this->getFileName(true)) {
         $url .= urlencode($fn);
     }
     return $url;
 }
Пример #5
0
 /**
  * Encode an internationalized domain name
  *
  * @param string $domain The domain name
  * @return string The encoded domain name
  */
 protected function encode($domain)
 {
     $objPunycode = new Punycode();
     return $objPunycode->encode($domain);
 }