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

Define API params in order to be able to filter correctly #413

Merged
merged 7 commits into from
Dec 18, 2024

Conversation

deluxetom
Copy link

@deluxetom deluxetom commented Dec 17, 2024

  • Added new tests to make sure only valid parameters are used
  • New interface method for each manipulator to know the API parameters used
  • no BC break

@@ -410,6 +409,7 @@ public function testGetAllParams()
$all_params = $this->server->getAllParams([
'w' => '100',
'p' => 'small',
'invalid' => '1',
Copy link
Author

Choose a reason for hiding this comment

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

@ADmad I realize I added some fixes that are out of scope of the issue, but this is the test fixing the cache path issue

I believe it shouldn't accept invalid parameters

Copy link
Collaborator

@ADmad ADmad left a comment

Choose a reason for hiding this comment

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

no BC break

Adding a new interface method is very much a BC break 🙂

But I think it's worth it in this case, given the improvement it provides.

src/Api/Api.php Outdated Show resolved Hide resolved
src/Api/Api.php Outdated
$params = [];

array_walk($this->manipulators, function (ManipulatorInterface $manipulator) use (&$params) {
foreach ($manipulator->getApiParams() as $param) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why loop through each instead of using array merge?

src/Manipulators/BaseManipulator.php Outdated Show resolved Hide resolved
src/Api/Api.php Outdated
Comment on lines 145 to 147
foreach ($manipulator->getApiParams() as $param) {
$this->apiParams[] = $param;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
foreach ($manipulator->getApiParams() as $param) {
$this->apiParams[] = $param;
}
$this->apiParams = array_merge($this->apiParams, $manipulator->getApiParams());

Copy link
Author

Choose a reason for hiding this comment

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

I was over-complicating this, thanks for pointing it out!

*
* @return list<string>
*/
abstract public function getApiParams(): array;
Copy link

Choose a reason for hiding this comment

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

We don't need this abstract method because it is defined already in ManipulatorInterface

Copy link
Author

@deluxetom deluxetom Dec 17, 2024

Choose a reason for hiding this comment

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

I agree, I was following what was done for the run method, I removed both from BaseManipulator

@ADmad ADmad merged commit 3cb6c58 into thephpleague:3.x Dec 18, 2024
9 checks passed
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.

3 participants