passing properties to recursive call if properties of top object are not specified

fixes #7717
close #10960
This commit is contained in:
Vladimir Khramov
2016-02-25 18:03:43 +10:00
committed by Carsten Brandt
parent 627233715b
commit c6d04644d3
3 changed files with 42 additions and 1 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.8 under development
-----------------------
- Bug #7717: Fixed the bug that `$properties` parameter in `ArrayHelper::toArray()` was not passed to recursive calls (quantum13)
- Bug #11088: Fixed bug with column name not being quoted correctly, when a quoted table name or a table name in prefix syntax was used (cebe, edgardmessias, Ni-san)
- Bug #9074: Fixed JS call `$('#grid').yiiGridView('getSelectedRows')` when `GridView::$showHeader` is set to false (NekitoSP, silverfire)
- Bug #9935: Fixed `yii\validators\EachValidator` does not invoke `validateAttribute()` method of the embedded validator (klimov-paul)

View File

@ -93,7 +93,7 @@ class BaseArrayHelper
}
}
return $recursive ? static::toArray($result) : $result;
return $recursive ? static::toArray($result, $properties) : $result;
} else {
return [$object];
}

View File

@ -27,6 +27,7 @@ class Post2 extends Object
class Post3 extends Object
{
public $id = 33;
/** @var Object */
public $subObject;
public function init()
@ -88,6 +89,45 @@ class ArrayHelperTest extends TestCase
'content' => 'test',
],
], ArrayHelper::toArray($object));
//recursive with attributes of object and subobject
$this->assertEquals([
'id' => 33,
'id_plus_1' => 34,
'subObject' => [
'id' => 123,
'id_plus_1' => 124,
],
], ArrayHelper::toArray($object, [
$object->className() => [
'id', 'subObject',
'id_plus_1' => function ($post) {
return $post->id+1;
}
],
$object->subObject->className() => [
'id',
'id_plus_1' => function ($post) {
return $post->id+1;
}
],
]));
//recursive with attributes of subobject only
$this->assertEquals([
'id' => 33,
'subObject' => [
'id' => 123,
'id_plus_1' => 124,
],
], ArrayHelper::toArray($object, [
$object->subObject->className() => [
'id',
'id_plus_1' => function ($post) {
return $post->id+1;
}
],
]));
}
public function testRemove()