[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/config/json/ -> PhabricatorConfigJSON.php (source)

   1  <?php
   2  
   3  final class PhabricatorConfigJSON {
   4    /**
   5     * Properly format a JSON value.
   6     *
   7     * @param wild Any value, but should be a raw value, not a string of JSON.
   8     * @return string
   9     */
  10    public static function prettyPrintJSON($value) {
  11      // Check not only that it's an array, but that it's an "unnatural" array
  12      // meaning that the keys aren't 0 -> size_of_array.
  13      if (is_array($value) && array_keys($value) != range(0, count($value) - 1)) {
  14        $result = id(new PhutilJSON())->encodeFormatted($value);
  15      } else {
  16        $result = json_encode($value);
  17      }
  18  
  19      // For readability, unescape forward slashes. These are normally escaped
  20      // to prevent the string "</script>" from appearing in a JSON literal,
  21      // but it's irrelevant here and makes reading paths more difficult than
  22      // necessary.
  23      $result = str_replace('\\/', '/', $result);
  24      return $result;
  25  
  26    }
  27  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1