-
-
Notifications
You must be signed in to change notification settings - Fork 841
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
fix(jsonapi): add support for pagination array parameter name #6319
base: main
Are you sure you want to change the base?
Changes from 4 commits
c2ddc80
69739f0
bd0d6a4
f270499
8b5d9e1
47e1c4b
8c88d0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,13 +219,38 @@ private function getGraphQlEnabled(?Operation $operation): bool | |
return $operation?->getPaginationEnabled() ?? $enabled; | ||
} | ||
|
||
/** | ||
* Extract pagination parameter | ||
* page[page] => $contextFilters['page'] with default configuration page_parameter_name: page | ||
* page[number] => $contextFilters['_page'][number] with configuration page_parameter_name: page[number]. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you mean that you configure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah exactly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To add more context to this, JSON:API consider query parameter such as two parameters named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah or There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a function test and a unit test? |
||
*/ | ||
private function extractParameter(array $contextFilters, string $parameterName): mixed | ||
{ | ||
preg_match_all("/[\w-]+/", $parameterName, $matches); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the need of this regex here, we know the possible parameter names no? I'd love a test to understand this better. |
||
foreach ($matches[0] as $i => $key) { | ||
if (0 === $i && 'page' === $key && \count($matches[0]) > 1) { | ||
$key = '_page'; | ||
} | ||
if (false === \is_array($contextFilters)) { | ||
return $contextFilters; | ||
} | ||
if (!\array_key_exists($key, $contextFilters)) { | ||
return null; | ||
} | ||
$contextFilters = $contextFilters[$key]; | ||
} | ||
|
||
return $contextFilters; | ||
} | ||
|
||
/** | ||
* Gets the given pagination parameter name from the given context. | ||
*/ | ||
private function getParameterFromContext(array $context, string $parameterName, mixed $default = null) | ||
private function getParameterFromContext(array $context, string $parameterName, mixed $default = null): mixed | ||
{ | ||
$filters = $context['filters'] ?? []; | ||
$filterValue = $this->extractParameter($filters, $parameterName); | ||
|
||
return \array_key_exists($parameterName, $filters) ? $filters[$parameterName] : $default; | ||
return $filterValue ?? $default; | ||
} | ||
} |
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.
The pagination parameter value?