Browse Source

Fix Request::data() and Hash::get() warnings and notices

Bryan Crowe 12 years ago
parent
commit
1eb08addd3
2 changed files with 13 additions and 10 deletions
  1. 2 2
      src/Network/Request.php
  2. 11 8
      src/Utility/Hash.php

+ 2 - 2
src/Network/Request.php

@@ -957,10 +957,10 @@ class Request implements \ArrayAccess {
  * You can write to any value, even paths/keys that do not exist, and the arrays
  * will be created for you.
  *
- * @param string $name,... Dot separated name of the value to read/write
+ * @param string|null $name Dot separated name of the value to read/write
  * @return mixed Either the value being read, or this so you can chain consecutive writes.
  */
-	public function data($name) {
+	public function data($name = null) {
 		$args = func_get_args();
 		if (count($args) === 2) {
 			$this->data = Hash::insert($this->data, $name, $args[1]);

+ 11 - 8
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 $path The path being searched for. Either a dot
- *   separated string, or an array of path segments.
+ * @param string|array|null $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, $default = null) {
+	public static function get(array $data, $path = null, $default = null) {
 		if (empty($data)) {
 			return $default;
 		}
@@ -54,11 +54,14 @@ class Hash {
 		} else {
 			$parts = $path;
 		}
-		foreach ($parts as $key) {
-			if (is_array($data) && isset($data[$key])) {
-				$data =& $data[$key];
-			} else {
-				return $default;
+
+		if ($path !== null) {
+			foreach ($parts as $key) {
+				if (is_array($data) && isset($data[$key])) {
+					$data =& $data[$key];
+				} else {
+					return $default;
+				}
 			}
 		}
 		return $data;