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

Pass ArgumentAccess with the knp_pager.items event #343

Merged
merged 3 commits into from
Sep 27, 2024

Conversation

mpdude
Copy link
Contributor

@mpdude mpdude commented Sep 24, 2024

This makes it possible for knp_pager.items event subscribers to access the pagination parameters, without having to be wired up by a dedicated knp_pager.before handler.

@mpdude mpdude force-pushed the pass-argument-access branch from 08e5ca6 to 5cd777b Compare September 24, 2024 21:01
This makes it possible for `knp_pager.items` event subscribers to access the pagination parameters, without having to be wired up by a dedicated `knp_pager.before` handler.
@mpdude mpdude force-pushed the pass-argument-access branch from 5cd777b to 6756cda Compare September 24, 2024 21:04
Comment on lines -431 to -438
$requestStack = $this->createRequestStack(['filterParam' => ['a.id', 'a.title'], 'filterValue' => '*er']);
$accessor = new RequestArgumentAccess($requestStack);
$p = new Paginator($dispatcher, $accessor);
$view = $p->paginate($query, 1, 10);
$items = $view->getItems();
$this->assertCount(2, $items);
$this->assertEquals('summer', $items[0]->getTitle());
$this->assertEquals('winter', $items[1]->getTitle());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test code never did what it was supposed to do – test a filterParam that is an array.

In fact, the FiltrationSubscriber would add the ORM\QuerySubscriber only on the first pass, and so we were always using (without noticing) the first RequestArgumentAccess instance where the filterParam is a scalar value.

In fact, the Symfony Request throws when trying to access a query parameter value that is not a scalar, as it was the case in this removed code.

@mpdude mpdude force-pushed the pass-argument-access branch from a9f5b89 to a5977de Compare September 24, 2024 21:22
@mpdude
Copy link
Contributor Author

mpdude commented Sep 25, 2024

@garak thank you for your feedback! I've addressed the objections.

@mpdude mpdude requested a review from garak September 25, 2024 17:20
@garak garak merged commit 311818b into KnpLabs:master Sep 27, 2024
7 checks passed
@mpdude mpdude deleted the pass-argument-access branch October 1, 2024 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants