diff --git a/Subscriber/KnpPaginateQuerySubscriber.php b/Subscriber/KnpPaginateQuerySubscriber.php index 113864b..dd1e3c8 100644 --- a/Subscriber/KnpPaginateQuerySubscriber.php +++ b/Subscriber/KnpPaginateQuerySubscriber.php @@ -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)); } } diff --git a/composer.json b/composer.json index ecdd46f..799d0a5 100644 --- a/composer.json +++ b/composer.json @@ -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",