Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Allow serializers to add metadata #81

Merged
merged 2 commits into from
Feb 24, 2016
Merged

Allow serializers to add metadata #81

merged 2 commits into from
Feb 24, 2016

Conversation

bwaidelich
Copy link
Contributor

With this change Serializers can provide metadata like::

class PostSerializer implements SerializerInterface
{
    // ...

    public function getMeta() {
        return ['some' => 'metadata'];
    }
}

Resolves #64

With this change Serializers can provide metadata like::

```
class PostSerializer implements SerializerInterface
{
    // ...

    public function getMeta() {
        return ['some' => 'metadata'];
    }
}
```

Resolves #64
@@ -167,12 +195,17 @@ public function comments($post)
return new Relationship(new Collection($post->comments, new CommentSerializer));
}
}
class PostSerializer4WithLinks extends PostSerializer4
class PostSerializer4WithLinksAndMeta extends PostSerializer4

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each class must be in a file by itself

if (! empty($this->meta)) {
$meta = $this->meta;
}
$serializerMeta = $this->serializer->getMeta();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pass $this->data into getMeta(), like we do with getLinks()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I'll post a follow-up

With this change Serializers can provide metadata like::

```
class PostSerializer implements SerializerInterface
{
    // ...

    public function getMeta($post) {
        return ['some' => 'metadata for ' . $post->id];
    }
}
```

Related #64
tobyzerner added a commit that referenced this pull request Feb 24, 2016
Allow serializers to add metadata
@tobyzerner tobyzerner merged commit d4a74e0 into tobyzerner:master Feb 24, 2016
@tobyzerner
Copy link
Owner

Perfect, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants