Skip to content

Commit

Permalink
Fixed "knplabs/knp-paginator-bundle" back to "^2.7", because "^4.0" i…
Browse files Browse the repository at this point in the history
…nstalls different version of knp-components if PHP>7.1. This makes it impossible to make KnpPaginateQuerySubscriber compatible for all cases, unless support for PHP 7.1 is dropped.
  • Loading branch information
pmishev committed Oct 23, 2019
1 parent 3a5a04b commit 6712c08
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
18 changes: 6 additions & 12 deletions Subscriber/KnpPaginateQuerySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,13 @@ protected function getSorting(ItemsEvent $event)
$sortField = null;
$sortDirection = 'asc';

$request = $this->requestStack->getCurrentRequest();
if ($request instanceof Request) {
$sortField = $request->get($event->options['sortFieldParameterName']);
$sortDirection = $request->get($event->options['sortDirectionParameterName'], 'desc');
$sortDirection = strtolower($sortDirection) === 'desc' ? 'desc' : 'asc';
if (isset($_GET[$event->options['sortFieldParameterName']])) {
$sortField = $_GET[$event->options['sortFieldParameterName']];
$sortDirection = isset($_GET[$event->options['sortDirectionParameterName']]) && strtolower($_GET[$event->options['sortDirectionParameterName']]) === 'desc' ? 'desc' : 'asc';

if ($sortField) {
// check if the requested sort field is in the sort whitelist
if (isset($event->options['sortFieldWhitelist']) && !in_array($sortField, $event->options['sortFieldWhitelist'])) {
throw new \UnexpectedValueException(
sprintf('Cannot sort by [%s] as it is not in the whitelist', $sortField)
);
}
// check if the requested sort field is in the sort whitelist
if (isset($event->options['sortFieldWhitelist']) && !in_array($sortField, $event->options['sortFieldWhitelist'])) {
throw new \UnexpectedValueException(sprintf('Cannot sort by [%s] as it is not in the whitelist', $sortField));
}
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"symfony/browser-kit": "^3.4 || ^4.0",

"monolog/monolog": "^1.0",
"knplabs/knp-paginator-bundle": "^4.0",
"knplabs/knp-paginator-bundle": "^2.7",
"squizlabs/php_codesniffer": "^3.0",
"php-coveralls/php-coveralls": "^2.1",
"escapestudios/symfony2-coding-standard": "^3.0",
Expand Down

0 comments on commit 6712c08

Please sign in to comment.