Skip to content

Commit

Permalink
Fix Request::data() and Hash::get() warnings and notices
Browse files Browse the repository at this point in the history
  • Loading branch information
bcrowe committed May 26, 2014
1 parent bd9c753 commit 1eb08ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Network/Request.php
Expand Up @@ -957,10 +957,10 @@ public function query($name) {
* 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]);
Expand Down
19 changes: 11 additions & 8 deletions src/Utility/Hash.php
Expand Up @@ -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;
}
Expand All @@ -54,11 +54,14 @@ public static function get(array $data, $path, $default = null) {
} 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;
Expand Down

0 comments on commit 1eb08ad

Please sign in to comment.