- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 28
Closed
Labels
help wantedstatus:ready for adoptionFeel free to implement this issue.Feel free to implement this issue.
Description
ArrayableTrait depends on Linkable and Link from yii-web for toArray():
public function toArray(array $fields = [], array $expand = [], $recursive = true)
{
    $data = [];
    foreach ($this->resolveFields($fields, $expand) as $field => $definition) {
        $attribute = is_string($definition) ? $this->$definition : $definition($this, $field);
        if ($recursive) {
            $nestedFields = $this->extractFieldsFor($fields, $field);
            $nestedExpand = $this->extractFieldsFor($expand, $field);
            if ($attribute instanceof Arrayable) {
                $attribute = $attribute->toArray($nestedFields, $nestedExpand);
            } elseif (is_array($attribute)) {
                $attribute = array_map(
                    function ($item) use ($nestedFields, $nestedExpand) {
                        if ($item instanceof Arrayable) {
                            return $item->toArray($nestedFields, $nestedExpand);
                        }
                        return $item;
                    },
                    $attribute
                );
            }
        }
        $data[$field] = $attribute;
    }
    if ($this instanceof Linkable) {
        $data['_links'] = Link::serialize($this->getLinks());
    }
    return $recursive ? ArrayHelper::toArray($data) : $data;
}As far as I know, this is a hack only used by REST, and could be moved to \yii\rest\Serializer::serializeModel(), as an additional $field
Am I missing something?
Metadata
Metadata
Assignees
Labels
help wantedstatus:ready for adoptionFeel free to implement this issue.Feel free to implement this issue.