src/Serializer.php
protected function serializeModel(Model $model, AdapterInterface $adapter)
    {
        $metadata = $model->getMetadata();
        $serialized = [
            'type'  => $model->getType(),
            'id'    => $model->getId(),
        ];
        if ($this->depth > 0) {
            // $this->includeResource($resource);
            return $serialized;
        }

        foreach ($metadata->getAttributes() as $key => $attrMeta) {
            if (false === $attrMeta->shouldSerialize()) {
                continue;
            }
            $value = $model->get($key);
            $serialized['attributes'][$key] = $this->serializeAttribute($value, $attrMeta);
        }

        foreach ($metadata->getEmbeds() as $key => $embeddedPropMeta) {
            if (false === $attrMeta->shouldSerialize()) {
                continue;
            }
            $value = $model->get($key);
            $serialized['attributes'][$key] = $this->serializeEmbed($value, $embeddedPropMeta);
        }

        $serialized['links'] = ['self' => $adapter->buildUrl($metadata, $model->getId())];

        $model->enableCollectionAutoInit(false);
        $this->increaseDepth();
        foreach ($metadata->getRelationships() as $key => $relMeta) {
            if (false === $relMeta->shouldSerialize()) {
                continue;
            }
            $relationship = $model->get($key);
            $serialized['relationships'][$key] = $this->serializeRelationship($model, $relationship, $relMeta, $adapter);
        }
        $this->decreaseDepth();
        $model->enableCollectionAutoInit(true);
        return $serialized;
    }
protected function serializeModel(Model $model, AdapterInterface $adapter)
    {
        $metadata = $model->getMetadata();
        $serialized = [
            'type'  => $model->getType(),
            'id'    => $model->getId(),
        ];
        if ($this->depth > 0) {
            // $this->includeResource($resource);
            return $serialized;
        }

        foreach ($metadata->getAttributes() as $key => $attrMeta) {
            if (false === $attrMeta->shouldSerialize()) {
                continue;
            }
            $value = $model->get($key);
            $serialized['attributes'][$key] = $this->serializeAttribute($value, $attrMeta);
        }

        foreach ($metadata->getEmbeds() as $key => $embeddedPropMeta) {
            if (false === $attrMeta->shouldSerialize()) {
                continue;
            }
            $value = $model->get($key);
            $serialized['attributes'][$key] = $this->serializeEmbed($value, $embeddedPropMeta);
        }

        $serialized['links'] = ['self' => $adapter->buildUrl($metadata, $model->getId())];

        $model->enableCollectionAutoInit(false);
        $this->increaseDepth();
        foreach ($metadata->getRelationships() as $key => $relMeta) {
            if (false === $relMeta->shouldSerialize()) {
                continue;
            }
            $relationship = $model->get($key);
            $serialized['relationships'][$key] = $this->serializeRelationship($model, $relationship, $relMeta, $adapter);
        }
        $this->decreaseDepth();
        $model->enableCollectionAutoInit(true);
        return $serialized;
    }
protected function serializeModel ( Model $ model , AdapterInterface $ adapter ) { $ metadata = $ model -> getMetadata ( ) ; $ serialized = [ 'type' => $ model -> getType ( ) , 'id' => $ model -> getId ( ) , ] ; if ( $ this -> depth > 0 ) { // $this->includeResource($resource); return $ serialized ; } foreach ( $ metadata -> getAttributes ( ) as $ key => $ attrMeta ) { if ( false === $ attrMeta -> shouldSerialize ( ) ) { continue ; } $ value = $ model -> get ( $ key ) ; $ serialized [ 'attributes' ] [ $ key ] = $ this -> serializeAttribute ( $ value , $ attrMeta ) ; } foreach ( $ metadata -> getEmbeds ( ) as $ key => $ embeddedPropMeta ) { if ( false === $ attrMeta -> shouldSerialize ( ) ) { continue ; } $ value = $ model -> get ( $ key ) ; $ serialized [ 'attributes' ] [ $ key ] = $ this -> serializeEmbed ( $ value , $ embeddedPropMeta ) ; } $ serialized [ 'links' ] = [ 'self' => $ adapter -> buildUrl ( $ metadata , $ model -> getId ( ) ) ] ; $ model -> enableCollectionAutoInit ( false ) ; $ this -> increaseDepth ( ) ; foreach ( $ metadata -> getRelationships ( ) as $ key => $ relMeta ) { if ( false === $ relMeta -> shouldSerialize ( ) ) { continue ; } $ relationship = $ model -> get ( $ key ) ; $ serialized [ 'relationships' ] [ $ key ] = $ this -> serializeRelationship ( $ model , $ relationship , $ relMeta , $ adapter ) ; } $ this -> decreaseDepth ( ) ; $ model -> enableCollectionAutoInit ( true ) ; return $ serialized ; }
Serializes the "interior" of a model.
This is the serialization that takes place outside of a "data" container.
Can be used for root model and relationship model serialization.

@param   Model               $model
@param   AdapterInterface    $adapter
@return  array
Serializes the interior of a model . This is the serialization that takes place outside of a data container . Can be used for root model and relationship model serialization .