MediaWiki
REL1_20
|
00001 <?php 00023 require_once __DIR__ . '/Services_JSON.php'; 00024 00028 class FormatJson { 00029 00043 public static function encode( $value, $isHtml = false ) { 00044 if ( !function_exists( 'json_encode' ) || ( $isHtml && version_compare( PHP_VERSION, '5.4.0', '<' ) ) ) { 00045 $json = new Services_JSON(); 00046 return $json->encode( $value, $isHtml ); 00047 } else { 00048 return json_encode( $value, $isHtml ? JSON_PRETTY_PRINT : 0 ); 00049 } 00050 } 00051 00063 public static function decode( $value, $assoc = false ) { 00064 if ( !function_exists( 'json_decode' ) ) { 00065 $json = $assoc ? new Services_JSON( SERVICES_JSON_LOOSE_TYPE ) : 00066 new Services_JSON(); 00067 $jsonDec = $json->decode( $value ); 00068 return $jsonDec; 00069 } else { 00070 return json_decode( $value, $assoc ); 00071 } 00072 } 00073 00074 }