MediaWiki
REL1_21
|
00001 <?php 00023 require_once __DIR__ . '/Services_JSON.php'; 00024 00028 class FormatJson { 00029 00038 public static function encode( $value, $pretty = false ) { 00039 if ( !function_exists( 'json_encode' ) || ( $pretty && version_compare( PHP_VERSION, '5.4.0', '<' ) ) ) { 00040 $json = new Services_JSON(); 00041 return $json->encode( $value, $pretty ); 00042 } else { 00043 return json_encode( $value, $pretty ? JSON_PRETTY_PRINT : 0 ); 00044 } 00045 } 00046 00058 public static function decode( $value, $assoc = false ) { 00059 if ( !function_exists( 'json_decode' ) ) { 00060 $json = $assoc ? new Services_JSON( SERVICES_JSON_LOOSE_TYPE ) : 00061 new Services_JSON(); 00062 $jsonDec = $json->decode( $value ); 00063 return $jsonDec; 00064 } else { 00065 return json_decode( $value, $assoc ); 00066 } 00067 } 00068 00069 }