Skip to content
This repository has been archived by the owner on Nov 20, 2019. It is now read-only.

Commit

Permalink
add polyfill to for the idn calls
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Nov 16, 2016
1 parent 5b64b3f commit 147d622
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
],
"require": {
"php": ">=5.5",
"symfony/polyfill-intl-icu": "^1.0",
"layershifter/tld-database": "^1.0",
"layershifter/tld-support": "^1.1"
"layershifter/tld-support": "^1.1",
"true/punycode": "^2.1.1"
},
"require-dev": {
"codeclimate/php-test-reporter": "dev-master",
Expand All @@ -29,7 +29,8 @@
},
"autoload": {
"files": [
"src/static.php"
"src/static.php",
"src/polyfill.php"
],
"psr-4": {
"LayerShifter\\TLDExtract\\": "src/"
Expand Down
52 changes: 52 additions & 0 deletions src/polyfill.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* TLDExtract: Library for extraction of domain parts e.g. TLD. Domain parser that uses Public Suffix List.
*
* @link https://github.com/layershifter/TLDExtract
*
* @copyright Copyright (c) 2016, Alexander Fedyashov
* @license https://raw.githubusercontent.com/layershifter/TLDExtract/master/LICENSE Apache 2.0 License
*/

namespace
{
use TrueBV\Punycode;

if (!function_exists('idn_to_utf8')) {

/**
* Polyfill for idn_to_utf8.
*
* @link http://php.net/manual/de/function.idn-to-utf8.php
*
* @param $domain
*
* @return string
*/
function idn_to_utf8($domain)
{
$punyCode = new Punycode();

return $punyCode->encode($domain);
}
}

if (!function_exists('idn_to_ascii')) {

/**
* Polyfill for idn_to_ascii.
*
* @link http://php.net/manual/de/function.idn-to-ascii.php
*
* @param string $domain
*
* @return string
*/
function idn_to_ascii($domain)
{
$punyCode = new Punycode();

return $punyCode->decode($domain);
}
}
}

0 comments on commit 147d622

Please sign in to comment.