-
Notifications
You must be signed in to change notification settings - Fork 201
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
Conversation
deluxetom
commented
Dec 17, 2024
•
edited
Loading
edited
- resolves All parameters are used for the cache path hash #412
- 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', |
There was a problem hiding this comment.
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
There was a problem hiding this 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
$params = []; | ||
|
||
array_walk($this->manipulators, function (ManipulatorInterface $manipulator) use (&$params) { | ||
foreach ($manipulator->getApiParams() as $param) { |
There was a problem hiding this comment.
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/Api/Api.php
Outdated
foreach ($manipulator->getApiParams() as $param) { | ||
$this->apiParams[] = $param; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foreach ($manipulator->getApiParams() as $param) { | |
$this->apiParams[] = $param; | |
} | |
$this->apiParams = array_merge($this->apiParams, $manipulator->getApiParams()); |
There was a problem hiding this comment.
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!
src/Manipulators/BaseManipulator.php
Outdated
* | ||
* @return list<string> | ||
*/ | ||
abstract public function getApiParams(): array; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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