mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-12 20:49:50 +00:00
commit
88f42eb362
2 changed files with 18 additions and 1 deletions
|
@ -229,6 +229,16 @@ class HashTest extends CakeTestCase {
|
|||
$this->assertEquals($data[1]['Article'], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get() with an invalid path
|
||||
*
|
||||
* @expectedException InvalidArgumentException
|
||||
* @return void
|
||||
*/
|
||||
public function testGetInvalidPath() {
|
||||
Hash::get(array('one' => 'two'), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test dimensions.
|
||||
*
|
||||
|
|
|
@ -38,6 +38,7 @@ class Hash {
|
|||
* @param string|array $path The path being searched for. Either a dot
|
||||
* separated string, or an array of path segments.
|
||||
* @param mixed $default The return value when the path does not exist
|
||||
* @throws InvalidArgumentException
|
||||
* @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
|
||||
*/
|
||||
|
@ -48,8 +49,13 @@ class Hash {
|
|||
if (is_string($path) || is_numeric($path)) {
|
||||
$parts = explode('.', $path);
|
||||
} else {
|
||||
$parts = $path;
|
||||
if (!is_array($path)) {
|
||||
throw new InvalidArgumentException(__d('cake_dev', 'Invalid Parameter %s, should be dot separated path or array.', $path));
|
||||
}
|
||||
|
||||
$parts = $path;
|
||||
}
|
||||
|
||||
foreach ($parts as $key) {
|
||||
if (is_array($data) && isset($data[$key])) {
|
||||
$data =& $data[$key];
|
||||
|
@ -57,6 +63,7 @@ class Hash {
|
|||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue