Browse Source

Return ->data in Request::data(), restore Hash::get(), add test for data() call with null

Bryan Crowe 11 years ago
parent
commit
47bebf4030
3 changed files with 14 additions and 11 deletions
  1. 4 1
      src/Network/Request.php
  2. 7 10
      src/Utility/Hash.php
  3. 3 0
      tests/TestCase/Network/RequestTest.php

+ 4 - 1
src/Network/Request.php

@@ -966,7 +966,10 @@ class Request implements \ArrayAccess {
 			$this->data = Hash::insert($this->data, $name, $args[1]);
 			return $this;
 		}
-		return Hash::get($this->data, $name);
+		if ($name !== null) {
+			return Hash::get($this->data, $name);
+		}
+		return $this->data;
 	}
 
 /**

+ 7 - 10
src/Utility/Hash.php

@@ -32,13 +32,13 @@ class Hash {
  * but is faster for simple read operations.
  *
  * @param array $data Array of data to operate on.
- * @param string|array|null $path The path being searched for. Either a dot
+ * @param string|array $path The path being searched for. Either a dot
  *   separated string, or an array of path segments, or null.
  * @param mixed $default The return value when the path does not exist
  * @return mixed The value fetched from the array, or null.
  * @link http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html#Hash::get
  */
-	public static function get(array $data, $path = null, $default = null) {
+	public static function get(array $data, $path, $default = null) {
 		if (empty($data)) {
 			return $default;
 		}
@@ -54,14 +54,11 @@ class Hash {
 		} else {
 			$parts = $path;
 		}
-
-		if ($path !== null) {
-			foreach ($parts as $key) {
-				if (is_array($data) && isset($data[$key])) {
-					$data =& $data[$key];
-				} else {
-					return $default;
-				}
+		foreach ($parts as $key) {
+			if (is_array($data) && isset($data[$key])) {
+				$data =& $data[$key];
+			} else {
+				return $default;
 			}
 		}
 		return $data;

+ 3 - 0
tests/TestCase/Network/RequestTest.php

@@ -1991,6 +1991,9 @@ class RequestTest extends TestCase {
 		$result = $request->data('Model');
 		$this->assertEquals($post['Model'], $result);
 
+		$result = $request->data();
+		$this->assertEquals($post, $result);
+
 		$result = $request->data('Model.imaginary');
 		$this->assertNull($result);
 	}