From b6eb79e51f4d098fea020536003c38c5c109b423 Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 13 Oct 2015 22:46:49 +0530 Subject: [PATCH] Use "toArray()" when available. Type casting object implementing ArrayAccess does not yield the expected array. --- src/Utility/Hash.php | 3 +++ tests/TestCase/Utility/HashTest.php | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Utility/Hash.php b/src/Utility/Hash.php index b770c174860..26454326134 100644 --- a/src/Utility/Hash.php +++ b/src/Utility/Hash.php @@ -156,6 +156,9 @@ public static function extract($data, $path) list($token, $conditions) = self::_splitConditions($token); foreach ($context[$_key] as $item) { + if (is_object($item) && method_exists($item, 'toArray')) { + $item = $item->toArray(); + } foreach ((array)$item as $k => $v) { if (static::_matchToken($k, $token)) { $next[] = $v; diff --git a/tests/TestCase/Utility/HashTest.php b/tests/TestCase/Utility/HashTest.php index 9bee78821b5..bb41a10c176 100644 --- a/tests/TestCase/Utility/HashTest.php +++ b/tests/TestCase/Utility/HashTest.php @@ -15,6 +15,7 @@ namespace Cake\Test\TestCase\Utility; use ArrayObject; +use Cake\ORM\Entity; use Cake\TestSuite\TestCase; use Cake\Utility\Hash; @@ -152,7 +153,7 @@ public static function articleData() public static function articleDataObject() { return new ArrayObject([ - new ArrayObject([ + new Entity([ 'Article' => new ArrayObject([ 'id' => '1', 'user_id' => '1',