예제 #1
0
 /**
  * Host is case-insensitive, normalise to lowercase and to ascii version of
  * IDN format
  */
 private function normaliseHost()
 {
     if (isset($this->parts['host'])) {
         $asciiHost = trim(strtolower(\Etechnika\IdnaConvert\IdnaConvert::encodeString($this->parts['host']->get())));
         $this->parts['host']->set($asciiHost);
     }
 }
예제 #2
0
 /**
  * @param string $strIn
  * @param string $strOut
  * @param string $booTrue
  *
  * @covers Etechnika\IdnaConvert\IdnaConvert::encode
  * @dataProvider providerEncodeString
  */
 public function testEncodeString($strIn, $strOut, $booTrue)
 {
     if ($booTrue) {
         $strOut === IdnaConvert::encodeString($strIn) ? $this->assertTrue(true) : $this->assertFalse(false);
     } else {
         $strOut !== IdnaConvert::encodeString($strIn) ? $this->assertTrue(true) : $this->assertFalse(false);
     }
 }
예제 #3
0
파일: helpers.php 프로젝트: takashiki/ourls
 function url_modify($url, $defaultScheme = 'http')
 {
     if (parse_url($url, PHP_URL_SCHEME) == null) {
         $url = $defaultScheme . '://' . trim($url, '/');
     }
     $url = (new URL\Normalizer($url, true, true))->normalize();
     if (filter_var(IdnaConvert::encodeString($url), FILTER_VALIDATE_URL) === false) {
         return false;
     } else {
         $fragment = parse_url($url, PHP_URL_FRAGMENT);
         return str_replace('#' . $fragment, '#' . urldecode($fragment), $url);
     }
 }
예제 #4
0
파일: Url.php 프로젝트: webignition/url
 /**
  *
  * @return string 
  */
 public function getRoot()
 {
     $rawRootUrl = '';
     if ($this->hasScheme()) {
         $rawRootUrl .= $this->getScheme() . ':';
     }
     if ($this->hasHost()) {
         $rawRootUrl .= '//';
         if ($this->hasCredentials()) {
             $rawRootUrl .= $this->getCredentials() . '@';
         }
         $host = (string) $this->getHost();
         if ($this->getConfiguration()->getConvertIdnToUtf8()) {
             $host = \Etechnika\IdnaConvert\IdnaConvert::decodeString($host);
         }
         $rawRootUrl .= $host;
     }
     if ($this->hasPort()) {
         $rawRootUrl .= ':' . $this->getPort();
     }
     return $rawRootUrl;
 }
예제 #5
0
 /**
  * Encode domain name
  *
  * @param string $strDomainName
  *
  * @return string
  */
 public static function idnaEncode($strDomainName)
 {
     return IdnaConvert::encodeString($strDomainName);
 }
예제 #6
0
파일: Host.php 프로젝트: webignition/url
 /**
  * 
  * @param \webignition\Url\Host\Host $comparator
  * @param array $excludeParts
  * @return boolean
  */
 public function isEquivalentTo(Host $comparator, $excludeParts = array())
 {
     $thisHost = new Host(\Etechnika\IdnaConvert\IdnaConvert::encodeString((string) $this));
     $comparatorHost = new Host(\Etechnika\IdnaConvert\IdnaConvert::encodeString((string) $comparator));
     if (!is_array($excludeParts) || count($excludeParts) == 0) {
         return $thisHost->equals($comparatorHost);
     }
     $thisParts = $this->excludeParts($thisHost->getParts(), $excludeParts);
     $comparatorParts = $this->excludeParts($comparatorHost->getParts(), $excludeParts);
     return $thisParts == $comparatorParts;
 }
예제 #7
0
파일: Instance.php 프로젝트: pdedkov/url
 /**
  * Для домена .рф конвертируем ссылку для проверок
  * @param string $link
  * @return array
  *
  */
 public static function convertToPunycode($link = null)
 {
     $Idna = new IdnaConvert();
     $link = self::httpLess($link);
     // для конветрации нужно выделить домен и конвертировать только его.
     $host = self::getHost($link);
     $artUrl = str_replace(self::getHost($link), '', $link);
     $res['linkPunyEnc'] = $Idna->encode($host) . $artUrl;
     $res['linkPunyDec'] = $Idna->decode(strtolower($host)) . $artUrl;
     // strtolower необходим из-за того, что idna_convert неверно декодирует при большебуквенном написании
     return $res;
 }
 /**
  * Энкодинг url
  *
  * @param $link
  * @return string
  */
 public static function encodeUrl($link)
 {
     $domain = parse_url($link, PHP_URL_HOST);
     $encoded_domain = IdnaConvert::encodeString($domain);
     return str_replace($domain, $encoded_domain, $link);
 }
예제 #9
0
 function decode($str)
 {
     return IdnaConvert::decodeString($str);
 }