TYPO3  7.6
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
idna_convert Class Reference

Public Member Functions

 __construct ($options=false)
 
 set_parameter ($option, $value=false)
 
 decode ($input, $one_time_encoding=false)
 
 encode ($decoded, $one_time_encoding=false)
 
 encode_uri ($uri)
 
 get_last_error ()
 
 getInstance ($params=array())
 
 singleton ($params=array())
 

Protected Member Functions

 _decode ($encoded)
 
 _encode ($decoded)
 
 _adapt ($delta, $npoints, $is_first)
 
 _encode_digit ($d)
 
 _decode_digit ($cp)
 
 _error ($error= '')
 
 _nameprep ($input)
 
 _hangul_decompose ($char)
 
 _hangul_compose ($input)
 
 _get_combining_class ($char)
 
 _apply_cannonical_ordering ($input)
 
 _combine ($input)
 
 _utf8_to_ucs4 ($input)
 
 _ucs4_to_utf8 ($input)
 
 _ucs4_to_ucs4_string ($input)
 
 _ucs4_string_to_ucs4 ($input)
 

Static Protected Member Functions

static byteLength ($string)
 

Protected Attributes

 $_punycode_prefix = 'xn--'
 
 $_invalid_ucs = 0x80000000
 
 $_max_ucs = 0x10FFFF
 
 $_base = 36
 
 $_tmin = 1
 
 $_tmax = 26
 
 $_skew = 38
 
 $_damp = 700
 
 $_initial_bias = 72
 
 $_initial_n = 0x80
 
 $_sbase = 0xAC00
 
 $_lbase = 0x1100
 
 $_vbase = 0x1161
 
 $_tbase = 0x11A7
 
 $_lcount = 19
 
 $_vcount = 21
 
 $_tcount = 28
 
 $_ncount = 588
 
 $_scount = 11172
 
 $_error = false
 
 $_api_encoding = 'utf8'
 
 $_allow_overlong = false
 
 $_strict_mode = false
 
 $_idn_version = 2003
 

Static Protected Attributes

static $_mb_string_overload = null
 
static $NP
 

Detailed Description

Encode/decode Internationalized Domain Names.

The class allows to convert internationalized domain names (see RFC 3490 for details) as they can be used with various registries worldwide to be translated between their original (localized) form and their encoded form as it will be used in the DNS (Domain Name System).

The class provides two public methods, encode() and decode(), which do exactly what you would expect them to do. You are allowed to use complete domain names, simple strings and complete email addresses as well. That means, that you might use any of the following notations:

Unicode input might be given as either UTF-8 string, UCS-4 string or UCS-4 array. Unicode output is available in the same formats. You can select your preferred format via set_paramter().

ACE input and output is always expected to be ASCII.

Author
Matthias Sommerfeld mso@p.nosp@m.hlyl.nosp@m.abs.d.nosp@m.e
Version
0.8.2 2014-09-15

Definition at line 52 of file idna_convert.class.php.

Constructor & Destructor Documentation

__construct (   $options = false)

the constructor

Parameters
array$options
Returns
boolean
Since
0.5.2

Definition at line 94 of file idna_convert.class.php.

References $_tcount, and set_parameter().

Member Function Documentation

_adapt (   $delta,
  $npoints,
  $is_first 
)
protected

Adapt the bias according to the current code point and position

Parameters
int$delta
int$npoints
int$is_first
Returns
int

Definition at line 553 of file idna_convert.class.php.

References $_base, and $_tmin.

Referenced by _decode(), and _encode().

_apply_cannonical_ordering (   $input)
protected

Applies the cannonical ordering of a decomposed UCS4 sequence

Parameters
arrayDecomposed UCS4 sequence
Returns
array Ordered USC4 sequence

Definition at line 747 of file idna_convert.class.php.

References _get_combining_class().

Referenced by _nameprep().

_combine (   $input)
protected

Do composition of a sequence of starter and non-starter

Parameters
arrayUCS4 Decomposed sequence
Returns
array Ordered USC4 sequence

Definition at line 779 of file idna_convert.class.php.

Referenced by _nameprep().

_decode (   $encoded)
protected

The actual decoding algorithm

Parameters
string
Returns
mixed

Definition at line 402 of file idna_convert.class.php.

References $_base, $_initial_bias, $_initial_n, $encoded, _adapt(), _decode_digit(), _error(), and _ucs4_to_utf8().

Referenced by decode().

_decode_digit (   $cp)
protected

Decode a certain digit

Parameters
int$cp
Returns
int

Definition at line 578 of file idna_convert.class.php.

References $_base.

Referenced by _decode().

_encode (   $decoded)
protected

The actual encoding algorithm

Parameters
string
Returns
mixed

Definition at line 459 of file idna_convert.class.php.

References $_base, $_initial_bias, $_initial_n, $encoded, _adapt(), _encode_digit(), _error(), _nameprep(), _utf8_to_ucs4(), and elseif.

Referenced by encode().

_encode_digit (   $d)
protected

Encoding a certain digit

Parameters
int$d
Returns
string

Definition at line 568 of file idna_convert.class.php.

Referenced by _encode().

_error (   $error = '')
protected

Internal error handling method

Parameters
string$error

Definition at line 588 of file idna_convert.class.php.

Referenced by _decode(), _encode(), _nameprep(), _ucs4_string_to_ucs4(), _ucs4_to_utf8(), _utf8_to_ucs4(), decode(), encode(), encode_uri(), and set_parameter().

_get_combining_class (   $char)
protected

Returns the combining class of a certain wide char

Parameters
integerWide char to check (32bit integer)
Returns
integer Combining class if found, else 0

Definition at line 737 of file idna_convert.class.php.

Referenced by _apply_cannonical_ordering(), and _nameprep().

_hangul_compose (   $input)
protected

Ccomposes a Hangul syllable (see http://www.unicode.org/unicode/reports/tr15/#Hangul

Parameters
arrayDecomposed UCS4 sequence
Returns
array UCS4 sequence with syllables composed

Definition at line 696 of file idna_convert.class.php.

References $_lbase, $_sbase, $_tbase, $_tcount, and $_vbase.

Referenced by _nameprep().

_hangul_decompose (   $char)
protected

Decomposes a Hangul syllable (see http://www.unicode.org/unicode/reports/tr15/#Hangul

Parameters
integer32bit UCS4 code point
Returns
array Either Hangul Syllable decomposed or original 32bit value as one value array

Definition at line 679 of file idna_convert.class.php.

References $_tcount.

Referenced by _nameprep().

_nameprep (   $input)
protected

Do Nameprep according to RFC3491 and RFC3454

Parameters
arrayUnicode Characters
Returns
string Unicode Characters, Nameprep'd

Definition at line 598 of file idna_convert.class.php.

References _apply_cannonical_ordering(), _combine(), _error(), _get_combining_class(), _hangul_compose(), _hangul_decompose(), and elseif.

Referenced by _encode().

_ucs4_string_to_ucs4 (   $input)
protected

Convert UCS-4 strin into UCS-4 garray

Parameters
string$input
Returns
array

Definition at line 940 of file idna_convert.class.php.

References _error().

Referenced by encode().

_ucs4_to_ucs4_string (   $input)
protected

Convert UCS-4 array into UCS-4 string

Parameters
array$input
Returns
string

Definition at line 923 of file idna_convert.class.php.

Referenced by decode().

_ucs4_to_utf8 (   $input)
protected

Convert UCS-4 string into UTF-8 string See _utf8_to_ucs4() for details

Parameters
string$input
Returns
string

Definition at line 897 of file idna_convert.class.php.

References _error(), and elseif.

Referenced by _decode(), and encode().

_utf8_to_ucs4 (   $input)
protected

This converts an UTF-8 encoded string to its UCS-4 representation By talking about UCS-4 "strings" we mean arrays of 32bit integers representing each of the "chars". This is due to PHP not being able to handle strings with bit depth different from 8. This apllies to the reverse method _ucs4_to_utf8(), too. The following UTF-8 encodings are supported: bytes bits representation 1 7 0xxxxxxx 2 11 110xxxxx 10xxxxxx 3 16 1110xxxx 10xxxxxx 10xxxxxx 4 21 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 5 26 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 6 31 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx Each x represents a bit that can be used to store character data. The five and six byte sequences are part of Annex D of ISO/IEC 10646-1:2000

Parameters
string$input
Returns
string

Definition at line 820 of file idna_convert.class.php.

References _error(), and elseif.

Referenced by _encode(), decode(), and encode().

static byteLength (   $string)
staticprotected

Gets the length of a string in bytes even if mbstring function overloading is turned on

Parameters
string$stringthe string for which to get the length.
Returns
integer the length of the string in bytes.

Definition at line 969 of file idna_convert.class.php.

decode (   $input,
  $one_time_encoding = false 
)

Decode a given ACE domain name

Parameters
stringDomain name (ACE string) [
stringDesired output encoding, see set_parameter]
Returns
string Decoded Domain name (UTF-8 or UCS-4)

Definition at line 177 of file idna_convert.class.php.

References _decode(), _error(), _ucs4_to_ucs4_string(), _utf8_to_ucs4(), and elseif.

encode (   $decoded,
  $one_time_encoding = false 
)

Encode a given UTF-8 domain name

Parameters
stringDomain name (UTF-8 or UCS-4) [
stringDesired input encoding, see set_parameter]
Returns
string Encoded Domain name (ACE string)

Definition at line 278 of file idna_convert.class.php.

References $encoded, _encode(), _error(), _ucs4_string_to_ucs4(), _ucs4_to_utf8(), and _utf8_to_ucs4().

Referenced by encode_uri().

encode_uri (   $uri)

Removes a weakness of encode(), which cannot properly handle URIs but instead encodes their path or query components, too.

Parameters
string$uriExpects the URI as a UTF-8 (or ASCII) string
Returns
string The URI encoded to Punycode, everything but the host component is left alone
Since
0.6.4

Definition at line 363 of file idna_convert.class.php.

References _error(), and encode().

get_last_error ( )

Use this method to get the last error ocurred

Parameters
void
Returns
string The last error, that occured

Definition at line 392 of file idna_convert.class.php.

References $_error.

getInstance (   $params = array())

Attempts to return a concrete IDNA instance.

Parameters
array$paramsSet of paramaters
Returns
idna_convert public

Definition at line 984 of file idna_convert.class.php.

Referenced by singleton().

set_parameter (   $option,
  $value = false 
)

Sets a new option value. Available options and values: [encoding - Use either UTF-8, UCS4 as array or UCS4 as string as input ('utf8' for UTF-8, 'ucs4_string' and 'ucs4_array' respectively for UCS4); The output is always UTF-8] [overlong - Unicode does not allow unnecessarily long encodings of chars, to allow this, set this parameter to true, else to false; default is false.] [strict - true: strict mode, good for registration purposes - Causes errors on failures; false: loose mode, ideal for "wildlife" applications by silently ignoring errors and returning the original input instead

Parameters
mixedParameter to set (string: single parameter; array of Parameter => Value pairs)
stringValue to use (if parameter 1 is a string)
Returns
boolean true on success, false otherwise

Definition at line 124 of file idna_convert.class.php.

References _error().

Referenced by __construct().

singleton (   $params = array())

Attempts to return a concrete IDNA instance for either php4 or php5, only creating a new instance if no IDNA instance with the same parameters currently exists.

Parameters
array$paramsSet of paramaters
Returns
object idna_convert public

Definition at line 999 of file idna_convert.class.php.

References getInstance().

Member Data Documentation

$_allow_overlong = false
protected

Definition at line 83 of file idna_convert.class.php.

$_api_encoding = 'utf8'
protected

Definition at line 82 of file idna_convert.class.php.

$_base = 36
protected

Definition at line 60 of file idna_convert.class.php.

Referenced by _adapt(), _decode(), _decode_digit(), and _encode().

$_damp = 700
protected

Definition at line 64 of file idna_convert.class.php.

$_error = false
protected

Definition at line 76 of file idna_convert.class.php.

Referenced by get_last_error().

$_idn_version = 2003
protected

Definition at line 85 of file idna_convert.class.php.

$_initial_bias = 72
protected

Definition at line 65 of file idna_convert.class.php.

Referenced by _decode(), and _encode().

$_initial_n = 0x80
protected

Definition at line 66 of file idna_convert.class.php.

Referenced by _decode(), and _encode().

$_invalid_ucs = 0x80000000
protected

Definition at line 58 of file idna_convert.class.php.

$_lbase = 0x1100
protected

Definition at line 68 of file idna_convert.class.php.

Referenced by _hangul_compose().

$_lcount = 19
protected

Definition at line 71 of file idna_convert.class.php.

$_max_ucs = 0x10FFFF
protected

Definition at line 59 of file idna_convert.class.php.

$_mb_string_overload = null
staticprotected

Definition at line 78 of file idna_convert.class.php.

$_ncount = 588
protected

Definition at line 74 of file idna_convert.class.php.

$_punycode_prefix = 'xn--'
protected

Definition at line 57 of file idna_convert.class.php.

$_sbase = 0xAC00
protected

Definition at line 67 of file idna_convert.class.php.

Referenced by _hangul_compose().

$_scount = 11172
protected

Definition at line 75 of file idna_convert.class.php.

$_skew = 38
protected

Definition at line 63 of file idna_convert.class.php.

$_strict_mode = false
protected

Definition at line 84 of file idna_convert.class.php.

$_tbase = 0x11A7
protected

Definition at line 70 of file idna_convert.class.php.

Referenced by _hangul_compose().

$_tcount = 28
protected

Definition at line 73 of file idna_convert.class.php.

Referenced by __construct(), _hangul_compose(), and _hangul_decompose().

$_tmax = 26
protected

Definition at line 62 of file idna_convert.class.php.

$_tmin = 1
protected

Definition at line 61 of file idna_convert.class.php.

Referenced by _adapt().

$_vbase = 0x1161
protected

Definition at line 69 of file idna_convert.class.php.

Referenced by _hangul_compose().

$_vcount = 21
protected

Definition at line 72 of file idna_convert.class.php.

$NP
staticprotected

Holds all relevant mapping tables See RFC3454 for details

array

Since
0.5.2

Definition at line 1019 of file idna_convert.class.php.