From 2d4a140a290e3b1d77f4da5773a521d9cc568b7c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 16 Dec 2017 11:54:24 -0700 Subject: [PATCH] Remove php 5.3 shim for json formatting --- CRM/Utils/REST.php | 95 +--------------------------------------------- 1 file changed, 1 insertion(+), 94 deletions(-) diff --git a/CRM/Utils/REST.php b/CRM/Utils/REST.php index bd88f42027..7802c47779 100644 --- a/CRM/Utils/REST.php +++ b/CRM/Utils/REST.php @@ -146,6 +146,7 @@ class CRM_Utils_REST { if (!empty($requestParams['json'])) { if (!empty($requestParams['prettyprint'])) { // Don't set content-type header for api explorer output + return json_encode(array_merge($result), JSON_PRETTY_PRINT + JSON_UNESCAPED_SLASHES + JSON_UNESCAPED_UNICODE); return self::jsonFormated(array_merge($result)); } CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); @@ -181,100 +182,6 @@ class CRM_Utils_REST { return $xml; } - /** - * @param $data - * - * @deprecated - switch to native JSON_PRETTY_PRINT when we drop support for php 5.3 - * - * @return string - */ - public static function jsonFormated($data) { - // If php is 5.4+ we can use the native method - if (defined('JSON_PRETTY_PRINT')) { - return json_encode($data, JSON_PRETTY_PRINT + JSON_UNESCAPED_SLASHES + JSON_UNESCAPED_UNICODE); - } - - // PHP 5.3 shim - $json = str_replace('\/', '/', json_encode($data)); - $tabcount = 0; - $result = ''; - $inquote = FALSE; - $inarray = FALSE; - $ignorenext = FALSE; - - $tab = "\t"; - $newline = "\n"; - - for ($i = 0; $i < strlen($json); $i++) { - $char = $json[$i]; - - if ($ignorenext) { - $result .= $char; - $ignorenext = FALSE; - } - else { - switch ($char) { - case '{': - if ($inquote) { - $result .= $char; - } - else { - $inarray = FALSE; - $tabcount++; - $result .= $char . $newline . str_repeat($tab, $tabcount); - } - break; - - case '}': - if ($inquote) { - $result .= $char; - } - else { - $tabcount--; - $result = trim($result) . $newline . str_repeat($tab, $tabcount) . $char; - } - break; - - case ',': - if ($inquote || $inarray) { - $result .= $char; - } - else { - $result .= $char . $newline . str_repeat($tab, $tabcount); - } - break; - - case '"': - $inquote = !$inquote; - $result .= $char; - break; - - case '\\': - if ($inquote) { - $ignorenext = TRUE; - } - $result .= $char; - break; - - case '[': - $inarray = TRUE; - $result .= $char; - break; - - case ']': - $inarray = FALSE; - $result .= $char; - break; - - default: - $result .= $char; - } - } - } - - return $result; - } - /** * @return array|int */ -- 2.25.1