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

Conversation

bwaidelich
Copy link
Contributor

With this change Serializers can provide links like::

class PostSerializer implements SerializerInterface
{
    // ...

    public function getLinks($post) {
        return ['self' => '/posts/' . $post->id];
    }
}

Partly resolves #64

With this change Serializers can provide links like::

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

    public function getLinks($post) {
        return ['self' => '/posts/' . $post->id];
    }
}
```

Partly resolves #64

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah well.. nit pick yourself ;)

bwaidelich referenced this pull request in bnchdrff/json-api Jan 25, 2016
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Resource constructor expects those parameters

@bwaidelich
Copy link
Contributor Author

FYI: This allows serializers to provide link relations (which I think is a crucial feature) partly resolving #64 – if this gets merged I'll gladly add another PR addressing the meta part

@bnchdrff
Copy link

I like. Hope this can get merged, as it's come in handy for a couple of my projects.

Copy link
Owner

Choose a reason for hiding this comment

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

Should a Resource instance's links take precedence over the serializer links?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I assumed (and what is covered by a test), but frankly I wasn't really sure about it.. And after thinking about it again it might be more flexible if a serializer can overrule resource links.
In the original patch by @bnchdrff it was also the other way around - should I swap it?

Copy link
Owner

Choose a reason for hiding this comment

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

Ah yes, didn't see the test and misread the order of array_merge arguments – the current behaviour is fine.

tobyzerner added a commit that referenced this pull request Jan 26, 2016
@tobyzerner tobyzerner merged commit 5b53806 into tobyzerner:master Jan 26, 2016
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.

Add links & meta to collection items via Serializer?
4 participants