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

Facilitate usage of filters #8

Open
Nek- opened this issue Apr 27, 2020 · 3 comments
Open

Facilitate usage of filters #8

Nek- opened this issue Apr 27, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@Nek-
Copy link
Member

Nek- commented Apr 27, 2020

The filters are used to filtering a collection of items.

It is common to want a filter applying only for a specific route.

Unfortunately, the method (supports(string $class)) doesn't have the request. To implement this logic you have to inject the requestStack and do the classic checks against null value.

It could be helpful and have sense to inject the current request to the support method (and only support)

This is BC IMHO, but what do you think @Nek- ?

This issue was originally written by @mcsky on biig repository.

@Nek-
Copy link
Member Author

Nek- commented Apr 27, 2020

I'm not sure it's a good idea to match directly on the request stack in case you want a route-related filter.

Here is an idea of implementation that keep BC. What do you think about adding a RouteAwareFilterInterface with a trait like this:

trait RouteAwareTrait
{
    private $route;
    public function setRoute(string $route) { $this->route = $route; }
}

But another idea (potentially better) is to add a new parameter extra_filters to the route we define. WDYT?

@Nek- Nek- added enhancement New feature or request good first issue Good for newcomers labels Apr 27, 2020
@Nek- Nek- removed the good first issue Good for newcomers label Aug 18, 2020
@Nek-
Copy link
Member Author

Nek- commented Aug 18, 2020

I'm not sure about this issue. Do you have an example @mcsky ?

@mcsky
Copy link

mcsky commented Nov 30, 2021

The only one I could see is

  • GET /line_items, line_items
  • GET /orders/{id}/line_items, order_line_items

Imagine a that use {id} to filter related line_items in a collection call.
You want this filter to be applied only on the order_line_items route.
But actually, it's a specific use case, so I guess you can depend on Request in your filter for this @Nek-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants