MediaWiki
REL1_22
|
JSON formatter wrapper class. More...
Static Public Member Functions | |
static | decode ($value, $assoc=false) |
Decodes a JSON string. | |
static | encode ($value, $pretty=false, $escaping=0) |
Returns the JSON representation of a value. | |
Public Attributes | |
const | ALL_OK = 3 |
Skip escaping as many characters as reasonably possible. | |
const | UTF8_OK = 1 |
Skip escaping most characters above U+007F for readability and compactness. | |
const | WS_CLEANUP_REGEX = '/(?<=[\[{])\n\s*+(?=[\]}])/' |
Regex that matches whitespace inside empty arrays and objects. | |
const | XMLMETA_OK = 2 |
Skip escaping the characters '<', '>', and '&', which have special meanings in HTML and XML. | |
Static Private Member Functions | |
static | encode53 ($value, $pretty, $escaping) |
JSON encoder wrapper for PHP 5.3, which lacks native support for some encoding options. | |
static | encode54 ($value, $pretty, $escaping) |
JSON encoder wrapper for PHP >= 5.4, which supports useful encoding options. | |
static | prettyPrint ($json) |
Adds non-significant whitespace to an existing JSON representation of an object. | |
Static Private Attributes | |
static | $badChars |
Characters problematic in JavaScript. | |
static | $badCharsEscaped |
Escape sequences for characters listed in FormatJson::$badChars. |
JSON formatter wrapper class.
Definition at line 26 of file FormatJson.php.
static FormatJson::decode | ( | $ | value, |
$ | assoc = false |
||
) | [static] |
Decodes a JSON string.
string | $value | The JSON string being decoded |
bool | $assoc | When true, returned objects will be converted into associative arrays. |
Definition at line 120 of file FormatJson.php.
References $value.
Referenced by ForeignAPIRepo\fetchImageQuery(), ResourceLoaderModule\getFileDependencies(), MessageBlobStore\getFromDB(), ForeignAPIRepo\getInfo(), MediaWikiSite\normalizePageName(), MessageBlobStore\reencodeBlob(), FormatJsonTest\testDecodeReturnType(), and MessageBlobStore\updateModule().
static FormatJson::encode | ( | $ | value, |
$ | pretty = false , |
||
$ | escaping = 0 |
||
) | [static] |
Returns the JSON representation of a value.
mixed | $value | The value to encode. Can be any type except a resource. |
bool | $pretty | If true, add non-significant whitespace to improve readability. |
int | $escaping | Bitfield consisting of _OK class constants |
Definition at line 103 of file FormatJson.php.
References $value, encode53(), and encode54().
Referenced by ApiFormatJson\execute(), GetConfiguration\execute(), MessageBlobStore\generateMessageBlob(), JSONRCFeedFormatter\getLine(), ResourceLoaderFileModule\getStyles(), MessageBlobStore\reencodeBlob(), FormatJsonTest\testEncodeAllOk(), FormatJsonTest\testEncodeDefault(), FormatJsonTest\testEncodePhpBug46944(), FormatJsonTest\testEncoderPrettyPrinting(), FormatJsonTest\testEncodeUtf8(), FormatJsonTest\testEncodeXmlMeta(), and GenerateJqueryMsgData\writeJavascriptFile().
static FormatJson::encode53 | ( | $ | value, |
$ | pretty, | ||
$ | escaping | ||
) | [static, private] |
JSON encoder wrapper for PHP 5.3, which lacks native support for some encoding options.
Therefore, the missing options are implemented here purely in PHP code.
mixed | $value | |
bool | $pretty | |
int | $escaping |
Definition at line 165 of file FormatJson.php.
References $options, $value, prettyPrint(), and XMLMETA_OK.
Referenced by encode().
static FormatJson::encode54 | ( | $ | value, |
$ | pretty, | ||
$ | escaping | ||
) | [static, private] |
JSON encoder wrapper for PHP >= 5.4, which supports useful encoding options.
mixed | $value | |
bool | $pretty | |
int | $escaping |
Definition at line 132 of file FormatJson.php.
References $options, $value, UTF8_OK, and XMLMETA_OK.
Referenced by encode().
static FormatJson::prettyPrint | ( | $ | json | ) | [static, private] |
Adds non-significant whitespace to an existing JSON representation of an object.
Only needed for PHP < 5.4, which lacks the JSON_PRETTY_PRINT option.
string | $json |
Definition at line 203 of file FormatJson.php.
Referenced by encode53().
FormatJson::$badChars [static, private] |
array( "\xe2\x80\xa8", "\xe2\x80\xa9", )
Characters problematic in JavaScript.
Definition at line 75 of file FormatJson.php.
FormatJson::$badCharsEscaped [static, private] |
array( '\u2028', '\u2029', )
Escape sequences for characters listed in FormatJson::$badChars.
Definition at line 83 of file FormatJson.php.
const FormatJson::ALL_OK = 3 |
Skip escaping as many characters as reasonably possible.
Definition at line 56 of file FormatJson.php.
Referenced by ApiFormatJson\execute(), and FormatJsonTest\testEncodeAllOk().
const FormatJson::UTF8_OK = 1 |
Skip escaping most characters above U+007F for readability and compactness.
This encoding option saves 3 to 8 bytes (uncompressed) for each such character; however, it could break compatibility with systems that incorrectly handle UTF-8.
Definition at line 35 of file FormatJson.php.
Referenced by encode54(), and FormatJsonTest\testEncodeUtf8().
const FormatJson::WS_CLEANUP_REGEX = '/(?<=[\[{])\n\s*+(?=[\]}])/' |
Regex that matches whitespace inside empty arrays and objects.
This doesn't affect regular strings inside the JSON because those can't have a real line break (
) in them, at this point they are already escaped as the string "\n" which this doesn't match.
Definition at line 67 of file FormatJson.php.
const FormatJson::XMLMETA_OK = 2 |
Skip escaping the characters '<', '>', and '&', which have special meanings in HTML and XML.
Definition at line 47 of file FormatJson.php.
Referenced by encode53(), encode54(), ApiFormatJson\execute(), and FormatJsonTest\testEncodeXmlMeta().