/** * 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); } }
/** * 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; }
/** * Энкодинг 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 encode($str) { return IdnaConvert::encodeString($str); }