CoreFiles by mySites.guru
ToUnicode.php37 lines, 969 bytes, from Joomla_4.4.3-Stable-Full_Package.zip
Raw History Compare with 4.4.2
md5
2632859709a274b6e694da235bb02645
sha1
945512a5da90e815176468319993b52484ee5696
sha256
d221d7f0073de808310aeeb13730e324b12a97837955ecba33dfba74eda9da56
<?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);
    }
}

The same content is in 238 releases, Joomla 4.0.0-alpha11 to 5.4.11. See them all, or every version of this file.