Browse Source

move pretty json and adjust readme

euromark 11 years ago
parent
commit
560c9cdf14
4 changed files with 70 additions and 72 deletions
  1. 1 67
      Config/bootstrap.php
  2. 66 0
      Lib/Utility/Utility.php
  3. 0 3
      Model/MyModel.php
  4. 3 2
      README.md

+ 1 - 67
Config/bootstrap.php

@@ -294,7 +294,7 @@ function returns($value) {
  * @return void
  * @return void
  */
  */
 function dump($var) {
 function dump($var) {
-	if (class_exists('Debugger')) {
+	if (!class_exists('Debugger')) {
 		App::uses('Debugger', 'Utility');
 		App::uses('Debugger', 'Utility');
 	}
 	}
 	return Debugger::dump($var);
 	return Debugger::dump($var);
@@ -510,69 +510,3 @@ function endsWith($haystack, $needle, $caseSensitive = false) {
 	}
 	}
 	return mb_strripos($haystack, $needle) === mb_strlen($haystack) - mb_strlen($needle);
 	return mb_strripos($haystack, $needle) === mb_strlen($haystack) - mb_strlen($needle);
 }
 }
-
-/**
- * PrettyJson
- *
- * @link https://github.com/ndejong/pretty_json/blob/master/pretty_json.php
- * @param string $json The original JSON string
- * @param string $ind The string to indent with
- * @return string
- */
-function prettyJson($json, $ind = "\t") {
-	// Replace any escaped \" marks so we don't get tripped up on quotemarks_counter
-	$tokens = preg_split('|([\{\}\]\[,])|', str_replace('\"', '~~PRETTY_JSON_QUOTEMARK~~', $json), -1, PREG_SPLIT_DELIM_CAPTURE);
-
-	$indent = 0;
-	$result = '';
-	$quotemarksCounter = 0;
-	$nextTokenUsePrefix = true;
-
-	foreach ($tokens as $token) {
-		$quotemarksCounter = $quotemarksCounter + (count(explode('"', $token)) - 1);
-
-		if ($token === '') {
-			continue;
-		}
-
-		if ($nextTokenUsePrefix) {
-			$prefix = str_repeat($ind, $indent);
-		} else {
-			$prefix = null;
-		}
-
-		// Determine if the quote marks are open or closed
-		if ($quotemarksCounter & 1) {
-			// odd - thus quotemarks open
-			$nextTokenUsePrefix = false;
-			$newLine = null;
-		} else {
-			// even - thus quotemarks closed
-			$nextTokenUsePrefix = true;
-			$newLine = "\n";
-		}
-
-		if ($token === "{" || $token === "[") {
-			$indent++;
-			$result .= $token . $newLine;
-		} elseif ($token === "}" || $token === "]") {
-			$indent--;
-
-			if ($indent >= 0) {
-				$prefix = str_repeat($ind, $indent);
-			}
-
-			if ($nextTokenUsePrefix) {
-				$result .= $newLine . $prefix . $token;
-			} else {
-				$result .= $newLine . $token;
-			}
-		} elseif ($token === ",") {
-			$result .= $token . $newLine;
-		} else {
-			$result .= $prefix . $token;
-		}
-	}
-	$result = str_replace('~~PRETTY_JSON_QUOTEMARK~~', '\"', $result);
-	return $result;
-}

+ 66 - 0
Lib/Utility/Utility.php

@@ -640,4 +640,70 @@ class Utility {
 		return round($elapsed, $precision);
 		return round($elapsed, $precision);
 	}
 	}
 
 
+	/**
+	 * Returns pretty JSON
+	 *
+	 * @link https://github.com/ndejong/pretty_json/blob/master/pretty_json.php
+	 * @param string $json The original JSON string
+	 * @param string $ind The string to indent with
+	 * @return string
+	 */
+	public function prettyJson($json, $ind = "\t") {
+		// Replace any escaped \" marks so we don't get tripped up on quotemarks_counter
+		$tokens = preg_split('|([\{\}\]\[,])|', str_replace('\"', '~~PRETTY_JSON_QUOTEMARK~~', $json), -1, PREG_SPLIT_DELIM_CAPTURE);
+
+		$indent = 0;
+		$result = '';
+		$quotemarksCounter = 0;
+		$nextTokenUsePrefix = true;
+
+		foreach ($tokens as $token) {
+			$quotemarksCounter = $quotemarksCounter + (count(explode('"', $token)) - 1);
+
+			if ($token === '') {
+				continue;
+			}
+
+			if ($nextTokenUsePrefix) {
+				$prefix = str_repeat($ind, $indent);
+			} else {
+				$prefix = null;
+			}
+
+			// Determine if the quote marks are open or closed
+			if ($quotemarksCounter & 1) {
+				// odd - thus quotemarks open
+				$nextTokenUsePrefix = false;
+				$newLine = null;
+			} else {
+				// even - thus quotemarks closed
+				$nextTokenUsePrefix = true;
+				$newLine = "\n";
+			}
+
+			if ($token === "{" || $token === "[") {
+				$indent++;
+				$result .= $token . $newLine;
+			} elseif ($token === "}" || $token === "]") {
+				$indent--;
+
+				if ($indent >= 0) {
+					$prefix = str_repeat($ind, $indent);
+				}
+
+				if ($nextTokenUsePrefix) {
+					$result .= $newLine . $prefix . $token;
+				} else {
+					$result .= $newLine . $token;
+				}
+			} elseif ($token === ",") {
+				$result .= $token . $newLine;
+			} else {
+				$result .= $prefix . $token;
+			}
+		}
+		$result = str_replace('~~PRETTY_JSON_QUOTEMARK~~', '\"', $result);
+		return $result;
+	}
+
 }
 }

+ 0 - 3
Model/MyModel.php

@@ -1559,7 +1559,6 @@ class MyModel extends Model {
 	 * @param STRING fieldName
 	 * @param STRING fieldName
 	 * @param integer id (cleaned!)
 	 * @param integer id (cleaned!)
 	 * @return ARRAY record: [Model][values],...
 	 * @return ARRAY record: [Model][values],...
-	 * AJAX?
 	 */
 	 */
 	public function toggleField($fieldName, $id) {
 	public function toggleField($fieldName, $id) {
 		$record = $this->get($id, array($this->primaryKey, $fieldName));
 		$record = $this->get($id, array($this->primaryKey, $fieldName));
@@ -1586,8 +1585,6 @@ class MyModel extends Model {
 		return $db->truncate($table);
 		return $db->truncate($table);
 	}
 	}
 
 
-/** Deep Lists **/
-
 	/**
 	/**
 	 * Recursive Dropdown Lists
 	 * Recursive Dropdown Lists
 	 * NEEDS tree behavior, NEEDS lft, rght, parent_id (!)
 	 * NEEDS tree behavior, NEEDS lft, rght, parent_id (!)

+ 3 - 2
README.md

@@ -84,10 +84,11 @@ A quick reference or some larger modules: [USAGE.md](https://github.com/dereurom
 * Auto-trim on POST (to make validation working properly).
 * Auto-trim on POST (to make validation working properly).
 * Auto-aliasing for models' "order" properties.
 * Auto-aliasing for models' "order" properties.
 * Disable cache also works for older IE versions.
 * Disable cache also works for older IE versions.
-* Redirect with additional encoding for Apache (if still using named params insteaf of query strings).
 * Default settings for Paginator, ... can be set using Configure.
 * Default settings for Paginator, ... can be set using Configure.
 * RSS and Ajax Views for better responses (Ajax also comes with an optional component).
 * RSS and Ajax Views for better responses (Ajax also comes with an optional component).
-* Minor misc. tweaks.
+* testAction() defaults to GET
+
+A full list of fixes and useful migration tweaks towards the next major version see [here]().
 
 
 ### Additional classes and features
 ### Additional classes and features