/** * 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); } }
/** * @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); } }
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); } }
/** * * @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; }
/** * Encode domain name * * @param string $strDomainName * * @return string */ public static function idnaEncode($strDomainName) { return IdnaConvert::encodeString($strDomainName); }
/** * * @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; }
/** * Для домена .рф конвертируем ссылку для проверок * @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); }
function decode($str) { return IdnaConvert::decodeString($str); }