CoreFiles by mySites.guru
ToUnicode.php34 lines, 797 bytes, from Joomla_6.0.3-rc1-Release_Candidate-Full_Package.zip
Raw History Compare with 6.0.2-rc1
md5
48912c7ce5759097bbe21453cbc9b44a
sha1
5f65cf59fe432ede6150978352e5a6e3092b9689
sha256
5980137612de2a6644430af1b7989a7c78a48c0fe7ea635db7982df86c2bedd8
<?php

declare(strict_types=1);

namespace Algo26\IdnaConvert;

use Algo26\IdnaConvert\Punycode\FromPunycode;

class ToUnicode extends AbstractIdnaConvert implements IdnaConvertInterface
{
    private FromPunycode $punycodeEncoder;

    public function __construct()
    {
        $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 50 releases, Joomla 6.0.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.