ソースを参照

Expect Jsonable to return arrays by default to be consistent across all depth levels.

Mark Scherer 10 年 前
コミット
fa212547d7

+ 1 - 1
Model/Behavior/JsonableBehavior.php

@@ -57,7 +57,7 @@ class JsonableBehavior extends ModelBehavior {
 			'depth' => 512,
 		],
 		'decodeParams' => [ // params for json_decode
-			'assoc' => false, // useful when working with multidimensional arrays
+			'assoc' => true, // useful when working with multidimensional arrays
 			'depth' => 512,
 			'options' => 0
 		]

+ 1 - 1
Model/Token.php

@@ -2,6 +2,7 @@
 App::uses('ToolsAppModel', 'Tools.Model');
 App::uses('CommonComponent', 'Tools.Controller/Component');
 App::uses('Hash', 'Utility');
+App::uses('RandomLib', 'Tools.Lib');
 
 /**
  * A generic model to hold tokens
@@ -194,7 +195,6 @@ class Token extends ToolsAppModel {
 		if (empty($length)) {
 			$length = $this->defaultLength;
 		}
-		App::uses('RandomLib', 'Tools.Lib');
 		return RandomLib::generatePassword($length);
 	}
 

+ 2 - 2
Test/Case/Model/Behavior/JsonableBehaviorTest.php

@@ -176,7 +176,7 @@ class JsonableBehaviorTest extends MyCakeTestCase {
 
 		// Test encode depth = 2
 		$this->Comment->Behaviors->unload('Jsonable');
-		$this->Comment->Behaviors->load('Tools.Jsonable', ['fields' => ['details'], 'encodeParams' => ['depth' => 2]]);
+		$this->Comment->Behaviors->load('Tools.Jsonable', ['fields' => ['details'], 'decodeParams' => ['assoc'=> false], 'encodeParams' => ['depth' => 2]]);
 
 		$data = [
 			'comment' => 'blabla',
@@ -194,7 +194,7 @@ class JsonableBehaviorTest extends MyCakeTestCase {
 	}
 
 	public function testDecodeParams() {
-		$this->Comment->Behaviors->load('Tools.Jsonable', ['fields' => ['details']]);
+		$this->Comment->Behaviors->load('Tools.Jsonable', ['fields' => ['details'], 'decodeParams' => ['assoc'=> false]]);
 
 		$data = [
 			'comment' => 'blabla',