Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusion in what is a collection for OkContent response #40

Open
Nek- opened this issue Sep 15, 2019 · 1 comment
Open

Confusion in what is a collection for OkContent response #40

Nek- opened this issue Sep 15, 2019 · 1 comment
Labels
good first issue Good for newcomers
Milestone

Comments

@Nek-
Copy link
Contributor

Nek- commented Sep 15, 2019

Example of the problem:

class MyController
{
    public function __invoke(ItemProvider $provider)
    {
        $items = array_filter($provider->getItems(), function ($item) {
            return $item->isPublic();
        });
        return new OkContent($items);
    }
}

The result will be miss-formatted collection. The reason is that the OkContent normalizer use the array as direct result. (which makes sense since we should be able to return "single object" as a form of array)

Here are 2 potential solutions, vote on the issue if you feel concerned with ❤️ or 🎉 for the second.

First solution ❤️

Adding a new method setCollection(true) to the OkContent response.

The previous code would look like that:

$response = new OkContent($items);
$response->setCollection(true);
return $response;

Second solution 🎉

Adding a new class "collection" to Melodiia. The previous code would look like that:

return new OkContent(new Collection($items));

WDYT?

@Nek- Nek- added the good first issue Good for newcomers label Sep 15, 2019
@Nek-
Copy link
Contributor Author

Nek- commented Sep 15, 2019

I'm in favor of the first one, considering we can already use new OkContent(new ArrayIterator($items)).

@Nek- Nek- added this to the v0.5 milestone Sep 15, 2019
@Nek- Nek- modified the milestones: v0.5, v0.6 Apr 2, 2020
Nek- added a commit to Nek-/Melodiia that referenced this issue Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant