29
29
/**
30
30
* Encode/decode Internationalized Domain Names.
31
31
*
32
- * The class allows to convert internationalized domain names
32
+ * The class allows one to convert internationalized domain names
33
33
* (see RFC 3490 for details) as they can be used with various registries worldwide
34
34
* to be translated between their original (localized) form and their encoded form
35
35
* as it will be used in the DNS (Domain Name System).
53
53
* @author Markus Nix <mnix@docuverse.de>
54
54
* @author Matthias Sommerfeld <mso@phlylabs.de>
55
55
* @author Stefan Neufeind <pear.neufeind@speedpartner.de>
56
- * @version $Id: IDNA2.php 305344 2010-11-14 23:52:42Z neufeind $
56
+ * @version $Id$
57
57
*/
58
58
class Net_IDNA2
59
59
{
@@ -2272,38 +2272,38 @@ public function setParams($option, $value = false)
2272
2272
2273
2273
foreach ($ option as $ k => $ v ) {
2274
2274
switch ($ k ) {
2275
- case 'encoding ' :
2276
- switch ($ v ) {
2277
- case 'utf8 ' :
2278
- case 'ucs4_string ' :
2279
- case 'ucs4_array ' :
2280
- $ this ->_api_encoding = $ v ;
2281
- break ;
2275
+ case 'encoding ' :
2276
+ switch ($ v ) {
2277
+ case 'utf8 ' :
2278
+ case 'ucs4_string ' :
2279
+ case 'ucs4_array ' :
2280
+ $ this ->_api_encoding = $ v ;
2281
+ break ;
2282
2282
2283
- default :
2284
- throw new InvalidArgumentException ('Set Parameter: Unknown parameter ' .$ v .' for option ' .$ k );
2285
- }
2283
+ default :
2284
+ throw new InvalidArgumentException ('Set Parameter: Unknown parameter ' .$ v .' for option ' .$ k );
2285
+ }
2286
2286
2287
- break ;
2287
+ break ;
2288
2288
2289
- case 'overlong ' :
2290
- $ this ->_allow_overlong = ($ v ) ? true : false ;
2291
- break ;
2289
+ case 'overlong ' :
2290
+ $ this ->_allow_overlong = ($ v ) ? true : false ;
2291
+ break ;
2292
2292
2293
- case 'strict ' :
2294
- $ this ->_strict_mode = ($ v ) ? true : false ;
2295
- break ;
2293
+ case 'strict ' :
2294
+ $ this ->_strict_mode = ($ v ) ? true : false ;
2295
+ break ;
2296
2296
2297
- case 'version ' :
2298
- if (in_array ($ v , array ('2003 ' , '2008 ' ))) {
2299
- $ this ->_version = $ v ;
2300
- } else {
2301
- throw new InvalidArgumentException ('Set Parameter: Invalid parameter ' .$ v .' for option ' .$ k );
2302
- }
2303
- break ;
2297
+ case 'version ' :
2298
+ if (in_array ($ v , array ('2003 ' , '2008 ' ))) {
2299
+ $ this ->_version = $ v ;
2300
+ } else {
2301
+ throw new InvalidArgumentException ('Set Parameter: Invalid parameter ' .$ v .' for option ' .$ k );
2302
+ }
2303
+ break ;
2304
2304
2305
- default :
2306
- return false ;
2305
+ default :
2306
+ return false ;
2307
2307
}
2308
2308
}
2309
2309
@@ -2327,15 +2327,15 @@ public function encode($decoded, $one_time_encoding = false)
2327
2327
// Forcing conversion of input to UCS4 array
2328
2328
// If one time encoding is given, use this, else the objects property
2329
2329
switch (($ one_time_encoding ) ? $ one_time_encoding : $ this ->_api_encoding ) {
2330
- case 'utf8 ' :
2331
- $ decoded = $ this ->_utf8_to_ucs4 ($ decoded );
2332
- break ;
2333
- case 'ucs4_string ' :
2334
- $ decoded = $ this ->_ucs4_string_to_ucs4 ($ decoded );
2335
- case 'ucs4_array ' : // No break; before this line. Catch case, but do nothing
2336
- break ;
2337
- default :
2338
- throw new InvalidArgumentException ('Unsupported input format ' );
2330
+ case 'utf8 ' :
2331
+ $ decoded = $ this ->_utf8_to_ucs4 ($ decoded );
2332
+ break ;
2333
+ case 'ucs4_string ' :
2334
+ $ decoded = $ this ->_ucs4_string_to_ucs4 ($ decoded );
2335
+ case 'ucs4_array ' : // No break; before this line. Catch case, but do nothing
2336
+ break ;
2337
+ default :
2338
+ throw new InvalidArgumentException ('Unsupported input format ' );
2339
2339
}
2340
2340
2341
2341
// No input, no output, what else did you expect?
@@ -2349,35 +2349,35 @@ public function encode($decoded, $one_time_encoding = false)
2349
2349
foreach ($ decoded as $ k => $ v ) {
2350
2350
// Make sure to use just the plain dot
2351
2351
switch ($ v ) {
2352
- case 0x3002 :
2353
- case 0xFF0E :
2354
- case 0xFF61 :
2355
- $ decoded [$ k ] = 0x2E ;
2352
+ case 0x3002 :
2353
+ case 0xFF0E :
2354
+ case 0xFF61 :
2355
+ $ decoded [$ k ] = 0x2E ;
2356
2356
// It's right, no break here
2357
2357
// The codepoints above have to be converted to dots anyway
2358
2358
2359
- // Stumbling across an anchoring character
2360
- case 0x2E :
2361
- case 0x2F :
2362
- case 0x3A :
2363
- case 0x3F :
2364
- case 0x40 :
2365
- // Neither email addresses nor URLs allowed in strict mode
2366
- if ($ this ->_strict_mode ) {
2367
- throw new InvalidArgumentException ('Neither email addresses nor URLs are allowed in strict mode. ' );
2368
- }
2369
- // Skip first char
2370
- if ($ k ) {
2371
- $ encoded = '' ;
2372
- $ encoded = $ this ->_encode (array_slice ($ decoded , $ last_begin , (($ k )-$ last_begin )));
2373
- if ($ encoded ) {
2374
- $ output .= $ encoded ;
2375
- } else {
2376
- $ output .= $ this ->_ucs4_to_utf8 (array_slice ($ decoded , $ last_begin , (($ k )-$ last_begin )));
2359
+ // Stumbling across an anchoring character
2360
+ case 0x2E :
2361
+ case 0x2F :
2362
+ case 0x3A :
2363
+ case 0x3F :
2364
+ case 0x40 :
2365
+ // Neither email addresses nor URLs allowed in strict mode
2366
+ if ($ this ->_strict_mode ) {
2367
+ throw new InvalidArgumentException ('Neither email addresses nor URLs are allowed in strict mode. ' );
2377
2368
}
2378
- $ output .= chr ($ decoded [$ k ]);
2379
- }
2380
- $ last_begin = $ k + 1 ;
2369
+ // Skip first char
2370
+ if ($ k ) {
2371
+ $ encoded = '' ;
2372
+ $ encoded = $ this ->_encode (array_slice ($ decoded , $ last_begin , (($ k )-$ last_begin )));
2373
+ if ($ encoded ) {
2374
+ $ output .= $ encoded ;
2375
+ } else {
2376
+ $ output .= $ this ->_ucs4_to_utf8 (array_slice ($ decoded , $ last_begin , (($ k )-$ last_begin )));
2377
+ }
2378
+ $ output .= chr ($ decoded [$ k ]);
2379
+ }
2380
+ $ last_begin = $ k + 1 ;
2381
2381
}
2382
2382
}
2383
2383
// Catch the rest of the string
@@ -2415,18 +2415,18 @@ public function decode($input, $one_time_encoding = false)
2415
2415
// Optionally set
2416
2416
if ($ one_time_encoding ) {
2417
2417
switch ($ one_time_encoding ) {
2418
- case 'utf8 ' :
2419
- case 'ucs4_string ' :
2420
- case 'ucs4_array ' :
2421
- break ;
2422
- default :
2423
- throw new InvalidArgumentException ('Unknown encoding ' .$ one_time_encoding );
2418
+ case 'utf8 ' :
2419
+ case 'ucs4_string ' :
2420
+ case 'ucs4_array ' :
2421
+ break ;
2422
+ default :
2423
+ throw new InvalidArgumentException ('Unknown encoding ' .$ one_time_encoding );
2424
2424
}
2425
2425
}
2426
2426
// Make sure to drop any newline characters around
2427
2427
$ input = trim ($ input );
2428
2428
2429
- // Negotiate input and try to determine, wether it is a plain string,
2429
+ // Negotiate input and try to determine, whether it is a plain string,
2430
2430
// an email address or something like a complete URL
2431
2431
if (strpos ($ input , '@ ' )) { // Maybe it is an email address
2432
2432
// No no in strict mode
@@ -2472,17 +2472,17 @@ public function decode($input, $one_time_encoding = false)
2472
2472
// The output is UTF-8 by default, other output formats need conversion here
2473
2473
// If one time encoding is given, use this, else the objects property
2474
2474
switch (($ one_time_encoding ) ? $ one_time_encoding : $ this ->_api_encoding ) {
2475
- case 'utf8 ' :
2476
- return $ return ;
2477
- break ;
2478
- case 'ucs4_string ' :
2479
- return $ this ->_ucs4_to_ucs4_string ($ this ->_utf8_to_ucs4 ($ return ));
2480
- break ;
2481
- case 'ucs4_array ' :
2482
- return $ this ->_utf8_to_ucs4 ($ return );
2483
- break ;
2484
- default :
2485
- throw new InvalidArgumentException ('Unsupported output format ' );
2475
+ case 'utf8 ' :
2476
+ return $ return ;
2477
+ break ;
2478
+ case 'ucs4_string ' :
2479
+ return $ this ->_ucs4_to_ucs4_string ($ this ->_utf8_to_ucs4 ($ return ));
2480
+ break ;
2481
+ case 'ucs4_array ' :
2482
+ return $ this ->_utf8_to_ucs4 ($ return );
2483
+ break ;
2484
+ default :
2485
+ throw new InvalidArgumentException ('Unsupported output format ' );
2486
2486
}
2487
2487
}
2488
2488
@@ -2678,7 +2678,7 @@ private function _decode($encoded)
2678
2678
return false ;
2679
2679
}
2680
2680
2681
- // Find last occurence of the delimiter
2681
+ // Find last occurrence of the delimiter
2682
2682
$ delim_pos = strrpos ($ encoded , '- ' );
2683
2683
2684
2684
if ($ delim_pos > self ::_byteLength ($ this ->_punycode_prefix )) {
@@ -2700,7 +2700,7 @@ private function _decode($encoded)
2700
2700
2701
2701
for ($ enco_idx = ($ delim_pos )? ($ delim_pos + 1 ) : 0 ; $ enco_idx < $ enco_len ; ++$ deco_len ) {
2702
2702
for ($ old_idx = $ idx , $ w = 1 , $ k = $ this ->_base ; 1 ; $ k += $ this ->_base ) {
2703
- $ digit = $ this ->_decodeDigit ($ encoded{ $ enco_idx ++} );
2703
+ $ digit = $ this ->_decodeDigit ($ encoded[ $ enco_idx ++] );
2704
2704
$ idx += $ digit * $ w ;
2705
2705
2706
2706
$ t = ($ k <= $ bias ) ?
@@ -2796,7 +2796,7 @@ private function _nameprep($input)
2796
2796
2797
2797
// Walking through the input array, performing the required steps on each of
2798
2798
// the input chars and putting the result into the output array
2799
- // While mapping required chars we apply the cannonical ordering
2799
+ // While mapping required chars we apply the canonical ordering
2800
2800
2801
2801
foreach ($ input as $ v ) {
2802
2802
// Map to nothing == skip that code point
@@ -2988,7 +2988,7 @@ private function _getCombiningClass($char)
2988
2988
}
2989
2989
2990
2990
/**
2991
- * Apllies the cannonical ordering of a decomposed UCS4 sequence.
2991
+ * Apllies the canonical ordering of a decomposed UCS4 sequence.
2992
2992
*
2993
2993
* @param array $input Decomposed UCS4 sequence
2994
2994
*
@@ -3112,9 +3112,9 @@ private function _utf8_to_ucs4($input)
3112
3112
$ mode = 'next ' ;
3113
3113
$ test = 'none ' ;
3114
3114
for ($ k = 0 ; $ k < $ inp_len ; ++$ k ) {
3115
- $ v = ord ($ input{ $ k } ); // Extract byte from input string
3115
+ $ v = ord ($ input[ $ k ] ); // Extract byte from input string
3116
3116
3117
- if ($ v < 128 ) { // We found an ASCII char - put into stirng as is
3117
+ if ($ v < 128 ) { // We found an ASCII char - put into string as is
3118
3118
$ output [$ out_len ] = $ v ;
3119
3119
++$ out_len ;
3120
3120
if ('add ' == $ mode ) {
@@ -3279,7 +3279,7 @@ private function _ucs4_string_to_ucs4($input)
3279
3279
$ out_len ++;
3280
3280
$ output [$ out_len ] = 0 ;
3281
3281
}
3282
- $ output [$ out_len ] += ord ($ input{ $ i } ) << (8 * (3 - ($ i % 4 ) ) );
3282
+ $ output [$ out_len ] += ord ($ input[ $ i ] ) << (8 * (3 - ($ i % 4 ) ) );
3283
3283
}
3284
3284
return $ output ;
3285
3285
}
@@ -3365,7 +3365,7 @@ private static function _byteLength($string)
3365
3365
* @return Net_IDNA2
3366
3366
* @access public
3367
3367
*/
3368
- function getInstance ($ params = array ())
3368
+ public static function getInstance ($ params = array ())
3369
3369
{
3370
3370
return new Net_IDNA2 ($ params );
3371
3371
}
@@ -3377,12 +3377,12 @@ function getInstance($params = array())
3377
3377
* only creating a new instance if no IDNA instance with the same
3378
3378
* parameters currently exists.
3379
3379
*
3380
- * @param array $params Set of paramaters
3380
+ * @param array $params Set of parameters
3381
3381
*
3382
3382
* @return object Net_IDNA2
3383
3383
* @access public
3384
3384
*/
3385
- function singleton ($ params = array ())
3385
+ public static function singleton ($ params = array ())
3386
3386
{
3387
3387
static $ instances ;
3388
3388
if (!isset ($ instances )) {
@@ -3399,4 +3399,4 @@ function singleton($params = array())
3399
3399
// }}}
3400
3400
}
3401
3401
3402
- ?>
3402
+ ?>
0 commit comments