Index: trunk/phase3/includes/json/FormatJson.php |
— | — | @@ -1,29 +1,31 @@ |
2 | 2 | <?php |
3 | | -/* |
4 | | - * simple wrapper for json_econde and json_decode that falls back on Services_JSON class |
| 3 | +/** |
| 4 | + * Simple wrapper for json_econde and json_decode that falls back on Services_JSON class |
5 | 5 | */ |
6 | | -if( !(defined( 'MEDIAWIKI' ) ) ) { |
| 6 | +if ( !defined( 'MEDIAWIKI' ) ) { |
7 | 7 | die( 1 ); |
8 | 8 | } |
9 | 9 | |
10 | 10 | class FormatJson { |
11 | | - public static function encode($value, $isHtml=false){ |
| 11 | + public static function encode( $value, $isHtml = false ) { |
12 | 12 | // Some versions of PHP have a broken json_encode, see PHP bug |
13 | 13 | // 46944. Test encoding an affected character (U+20000) to |
14 | 14 | // avoid this. |
15 | | - if (!function_exists('json_encode') || $isHtml || strtolower(json_encode("\xf0\xa0\x80\x80")) != '\ud840\udc00') { |
| 15 | + if ( !function_exists( 'json_encode' ) || $isHtml || strtolower( json_encode( "\xf0\xa0\x80\x80" ) ) != '\ud840\udc00' ) { |
16 | 16 | $json = new Services_JSON(); |
17 | | - return $json->encode($value, $isHtml) ; |
| 17 | + return $json->encode( $value, $isHtml ); |
18 | 18 | } else { |
19 | | - return json_encode($value); |
| 19 | + return json_encode( $value ); |
20 | 20 | } |
21 | 21 | } |
22 | | - public static function decode( $value, $assoc=false ){ |
23 | | - if (!function_exists('json_decode') ) { |
| 22 | + |
| 23 | + public static function decode( $value, $assoc = false ) { |
| 24 | + if ( !function_exists( 'json_decode' ) ) { |
24 | 25 | $json = new Services_JSON(); |
25 | 26 | $jsonDec = $json->decode( $value ); |
26 | | - if( $assoc ) |
| 27 | + if( $assoc ) { |
27 | 28 | $jsonDec = wfObjectToArray( $jsonDec ); |
| 29 | + } |
28 | 30 | return $jsonDec; |
29 | 31 | } else { |
30 | 32 | return json_decode( $value, $assoc ); |