mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-14 19:28:34 +01:00
passing properties to recursive call if properties of top object are not specified
fixes #7717 close #10960
This commit is contained in:
committed by
Carsten Brandt
parent
627233715b
commit
c6d04644d3
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user