phpcs fix
[civicrm-core.git] / CRM / Utils / REST.php
index 670de8012e7b13e1dcbb76caf2d4ca8947160e97..e1424833fd53d131b48e92eb02f495f9e98fcc6b 100644 (file)
@@ -3,7 +3,7 @@
    +--------------------------------------------------------------------+
    | CiviCRM version 4.6                                                |
    +--------------------------------------------------------------------+
-   | Copyright CiviCRM LLC (c) 2004-2014                                |
+   | Copyright CiviCRM LLC (c) 2004-2015                                |
    +--------------------------------------------------------------------+
    | This file is a part of CiviCRM.                                    |
    |                                                                    |
@@ -29,7 +29,7 @@
  * This class handles all REST client requests.
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  *
  */
 class CRM_Utils_REST {
@@ -146,12 +146,11 @@ class CRM_Utils_REST {
 
     if (!empty($requestParams['json'])) {
       header('Content-Type: application/json');
-      $json = json_encode(array_merge($result));
       if (!empty($requestParams['prettyprint'])) {
         // Used by the api explorer
-        return self::jsonFormated($json);
+        return self::jsonFormated(array_merge($result));
       }
-      return $json;
+      return json_encode(array_merge($result));
     }
 
     if (isset($result['count'])) {
@@ -179,11 +178,20 @@ class CRM_Utils_REST {
   }
 
   /**
-   * @param $json
+   * @param $data
+   *
+   * @deprecated - switch to native JSON_PRETTY_PRINT when we drop support for php 5.3
    *
    * @return string
    */
-  public static function jsonFormated($json) {
+  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;
@@ -504,7 +512,7 @@ class CRM_Utils_REST {
 
     }
     else {
-      $content = "<!-- .tpl file embeded: $tpl -->\n";
+      $content = "<!-- .tpl file embedded: $tpl -->\n";
       CRM_Utils_System::appendTPLFile($tpl, $content);
       echo $content . $smarty->fetch($tpl);
       CRM_Utils_System::civiExit();