primo commit
This commit is contained in:
37
libraries/vendor/algo26-matthias/idna-convert/src/ToUnicode.php
vendored
Normal file
37
libraries/vendor/algo26-matthias/idna-convert/src/ToUnicode.php
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace Algo26\IdnaConvert;
|
||||
|
||||
use Algo26\IdnaConvert\Punycode\FromPunycode;
|
||||
use Algo26\IdnaConvert\TranscodeUnicode\TranscodeUnicode;
|
||||
|
||||
class ToUnicode extends AbstractIdnaConvert implements IdnaConvertInterface
|
||||
{
|
||||
/** @var TranscodeUnicode */
|
||||
private $unicodeTransCoder;
|
||||
|
||||
/** @var FromPunycode */
|
||||
private $punycodeEncoder;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->unicodeTransCoder = new TranscodeUnicode();
|
||||
$this->punycodeEncoder = new FromPunycode();
|
||||
}
|
||||
|
||||
public function convert(string $host): string
|
||||
{
|
||||
// Drop any whitespace around
|
||||
$input = trim($host);
|
||||
|
||||
$hostLabels = explode('.', $input);
|
||||
foreach ($hostLabels as $index => $label) {
|
||||
$return = $this->punycodeEncoder->convert($label);
|
||||
if (!$return) {
|
||||
$return = $label;
|
||||
}
|
||||
$hostLabels[$index] = $return;
|
||||
}
|
||||
|
||||
return implode('.', $hostLabels);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user