mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 21:41:19 +08:00
Added support of JsonSerializable interface to ArrayableTrait (#17888)
This commit is contained in:
@ -128,12 +128,16 @@ trait ArrayableTrait
|
||||
if ($recursive) {
|
||||
$nestedFields = $this->extractFieldsFor($fields, $field);
|
||||
$nestedExpand = $this->extractFieldsFor($expand, $field);
|
||||
if ($attribute instanceof Arrayable) {
|
||||
if ($attribute instanceof \JsonSerializable) {
|
||||
$attribute = $attribute->jsonSerialize();
|
||||
} elseif ($attribute instanceof Arrayable) {
|
||||
$attribute = $attribute->toArray($nestedFields, $nestedExpand);
|
||||
} elseif (is_array($attribute)) {
|
||||
$attribute = array_map(
|
||||
function ($item) use ($nestedFields, $nestedExpand) {
|
||||
if ($item instanceof Arrayable) {
|
||||
if ($item instanceof \JsonSerializable) {
|
||||
return $item->jsonSerialize();
|
||||
} elseif ($item instanceof Arrayable) {
|
||||
return $item->toArray($nestedFields, $nestedExpand);
|
||||
}
|
||||
return $item;
|
||||
|
||||
Reference in New Issue
Block a user