@@ 45-57 (lines=13) @@ | ||
42 | * |
|
43 | * @return string Punycode representation in ASCII |
|
44 | */ |
|
45 | public function encode($input): string |
|
46 | { |
|
47 | if ($this->idnSupport === true) { |
|
48 | // https://git.ispconfig.org/ispconfig/ispconfig3/blob/master/interface/lib/classes/functions.inc.php#L305 |
|
49 | if (defined('IDNA_NONTRANSITIONAL_TO_ASCII') && defined('INTL_IDNA_VARIANT_UTS46') && constant('IDNA_NONTRANSITIONAL_TO_ASCII')) { |
|
50 | return idn_to_ascii($input, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46); |
|
51 | } else { |
|
52 | return idn_to_ascii($input); |
|
53 | } |
|
54 | } |
|
55 | ||
56 | return self::$punycode->encode($input); |
|
57 | } |
|
58 | ||
59 | /** |
|
60 | * Decode a Punycode domain name to its Unicode counterpart |
|
@@ 66-77 (lines=12) @@ | ||
63 | * |
|
64 | * @return string Unicode domain name |
|
65 | */ |
|
66 | public function decode($input): string |
|
67 | { |
|
68 | if ($this->idnSupport === true) { |
|
69 | if (defined('IDNA_NONTRANSITIONAL_TO_UNICODE') && defined('INTL_IDNA_VARIANT_UTS46') && constant('IDNA_NONTRANSITIONAL_TO_UNICODE')) { |
|
70 | return idn_to_utf8($input, IDNA_NONTRANSITIONAL_TO_UNICODE, INTL_IDNA_VARIANT_UTS46); |
|
71 | } else { |
|
72 | return idn_to_utf8($input); |
|
73 | } |
|
74 | } |
|
75 | ||
76 | return self::$punycode->decode($input); |
|
77 | } |
|
78 | } |
|
79 |