-
Notifications
You must be signed in to change notification settings - Fork 34
feat(package): remove dependency on ext-intl #8
feat(package): remove dependency on ext-intl #8
Conversation
@layershifter dont know why the scrutinizer-ci errored on composer |
@alexander-schranz Thanks for PR! I'm glad to use Symfony's polyfill, but it doesn't provide According to PHP docs So, here is TODO list for removing
Looks little complicated 😄 I'll start to work on it today. |
@layershifter great, thank you! mbstring can also be used from symfony: https://github.com/symfony/polyfill-mbstring |
We've made a new release of https://github.com/true/php-punycode in which https://github.com/symfony/polyfill-mbstring can be used |
thank you @Marlinc |
10ed760
to
147d622
Compare
147d622
to
ef16430
Compare
Two steps completed, let's complete last 😄 I think it's not good idea to send Let's make a small refactoring there, it will give following advantages:
Extract.php /**
* @var int Value of extraction options.
*/
private $extractionMode;
+ /**
+ * @var IDN Object of TLDExtract\IDN class.
+ */
+ private $idn;
/**
* @var string Name of class that will store results of parsing.
*/
private $resultClassName; public function __construct($databaseFile = null, $resultClassName = null, $extractionMode = null)
{
+ $this->idn = new IDN();
$this->suffixStore = new Store($databaseFile); if ($isPunycoded) {
- $hostname = idn_to_utf8($hostname);
+ $hostname = $this->idn->toUTF8($hostname);
} - return $isPunycoded ? idn_to_ascii($suffix) : $suffix;
+ return $isPunycoded ? $this->idn->toASCII($hostname) : $suffix; IDN.php<?php
namespace LayerShifter\TLDExtract;
use TrueBV\Punycode;
/**
* Class that transforms IDN domains, if `intl` extension present uses it.
*/
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.
*
* @param string $domain Domain to convert in IDNA ASCII-compatible format.
*
* @return string
*/
public function toASCII($domain)
{
if ($this->transformer) {
return $this->transformer->encode($domain);
}
return idn_to_ascii($domain);
}
/**
* Converts domain name from IDNA ASCII to Unicode.
*
* @param string $domain Domain to convert in Unicode format.
*
* @return string
*/
public function toUTF8($domain)
{
if ($this->transformer) {
return $this->transformer->decode($domain);
}
return idn_to_utf8($domain);
}
} IDNTest.php<?php
namespace LayerShifter\TLDExtract\Tests;
use LayerShifter\TLDExtract\IDN;
use TrueBV\Punycode;
/**
* Tests for IDN class.
*/
class IDNTest extends \PHPUnit_Framework_TestCase
{
/**
* @var IDN Object for tests
*/
private $idn;
/**
* Method that setups test's environment.
*
* @return void
*/
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.
*
* @return void
*/
public function testToASCII()
{
$this->assertEquals('xn--tst-qla.de', $this->idn->toASCII('täst.de'));
}
/**
* Tests toUTF8() method.
*
* @return void
*/
public function testToUTF8()
{
$this->assertEquals('täst.de', $this->idn->toUTF8('xn--tst-qla.de'));
}
} |
@alexander-schranz Thanks much, I'll merge it and prepare release 👍 |
@layershifter that was to early 🙈 |
Yep, I saw that CI tests are failed, will fix it before release 🐵 |
fixes #7