From d5dbf11200275435600b5629ff5bbe64a85d2193 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 6 Feb 2019 10:10:00 +0100 Subject: [PATCH] Remove punycode as dependency (#39) * Remove punycode as dependencie * Use symfony polyfill * Remove punycode test --- composer.json | 2 +- src/IDN.php | 24 ------------------------ tests/IDNTest.php | 17 ----------------- 3 files changed, 1 insertion(+), 42 deletions(-) diff --git a/composer.json b/composer.json index 6b2f2fb..52fb041 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "php": "^5.5.0 || ^7.0", "layershifter/tld-database": "^1.0", "layershifter/tld-support": "^1.1", - "true/punycode": "^2.1.1" + "symfony/polyfill-intl-idn": "^1.10" }, "require-dev": { "phpmd/phpmd": "@stable", diff --git a/src/IDN.php b/src/IDN.php index b919e5b..ee140f0 100644 --- a/src/IDN.php +++ b/src/IDN.php @@ -9,22 +9,6 @@ */ class IDN { - - /** - * @var Punycode Object of TrueBV\Punycode class. - */ - private $transformer; - - /** - * Constructor. - */ - public function __construct() - { - if (!function_exists('\idn_to_utf8')) { - $this->transformer = new Punycode(); - } - } - /** * Converts domain name from Unicode to IDNA ASCII. * @@ -34,10 +18,6 @@ public function __construct() */ public function toASCII($domain) { - if ($this->transformer) { - return $this->transformer->encode($domain); - } - if (defined('INTL_IDNA_VARIANT_UTS46')) { return idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46); } @@ -54,10 +34,6 @@ public function toASCII($domain) */ public function toUTF8($domain) { - if ($this->transformer) { - return $this->transformer->decode($domain); - } - if (defined('INTL_IDNA_VARIANT_UTS46')) { return idn_to_utf8($domain, 0, INTL_IDNA_VARIANT_UTS46); } diff --git a/tests/IDNTest.php b/tests/IDNTest.php index 80393e8..fe100ae 100644 --- a/tests/IDNTest.php +++ b/tests/IDNTest.php @@ -3,7 +3,6 @@ namespace LayerShifter\TLDExtract\Tests; use LayerShifter\TLDExtract\IDN; -use TrueBV\Punycode; /** * Tests for IDN class. @@ -26,22 +25,6 @@ protected function setUp() $this->idn = new IDN(); } - /** - * Tests constructor(), ensures that transformer isn't loaded when `intl` extension present. - * - * @void - */ - public function testConstructor() - { - if (function_exists('\idn_to_utf8')) { - $this->assertAttributeInternalType('null', 'transformer', $this->idn); - - return; - } - - $this->assertAttributeInstanceOf(Punycode::class, 'transformer', $this->idn); - } - /** * Tests toASCII() method. *