Skip to content

Commit 1279fab

Browse files
authored
Merge pull request #1990 from pkruithof/fix-symfony8-deprecation
Fix deprecated Symfony method call
2 parents 58b607f + 6b2b985 commit 1279fab

1 file changed

Lines changed: 8 additions & 28 deletions

File tree

‎src/Subscriber/PaginateElasticaQuerySubscriber.php‎

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,28 @@
1212
namespace FOS\ElasticaBundle\Subscriber;
1313

1414
use FOS\ElasticaBundle\Paginator\PaginatorAdapterInterface;
15-
use FOS\ElasticaBundle\Paginator\PartialResultsInterface;
1615
use Knp\Component\Pager\Event\ItemsEvent;
1716
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1817
use Symfony\Component\HttpFoundation\Request;
1918
use Symfony\Component\HttpFoundation\RequestStack;
2019

2120
class PaginateElasticaQuerySubscriber implements EventSubscriberInterface
2221
{
23-
private RequestStack $requestStack;
24-
25-
public function __construct(RequestStack $requestStack)
22+
public function __construct(private RequestStack $requestStack)
2623
{
27-
$this->requestStack = $requestStack;
2824
}
2925

30-
/**
31-
* @return void
32-
*/
33-
public function items(ItemsEvent $event)
26+
public function items(ItemsEvent $event): void
3427
{
3528
if ($event->target instanceof PaginatorAdapterInterface) {
3629
// Add sort to query
3730
$this->setSorting($event);
3831

39-
/** @var PartialResultsInterface $results */
4032
$results = $event->target->getResults($event->getOffset(), $event->getLimit());
4133

4234
$event->count = $results->getTotalHits();
4335
$event->items = $results->toArray();
44-
$aggregations = $results->getAggregations();
45-
if (null != $aggregations) {
46-
$event->setCustomPaginationParameter('aggregations', $aggregations);
47-
}
36+
$event->setCustomPaginationParameter('aggregations', $results->getAggregations());
4837

4938
$event->stopPropagation();
5039
}
@@ -59,10 +48,8 @@ public static function getSubscribedEvents(): array
5948

6049
/**
6150
* Adds knp paging sort to query.
62-
*
63-
* @return void
6451
*/
65-
protected function setSorting(ItemsEvent $event)
52+
protected function setSorting(ItemsEvent $event): void
6653
{
6754
$options = $event->options ?? [];
6855
$sortField = $this->getFromRequest($options['sortFieldParameterName'] ?? null);
@@ -79,12 +66,11 @@ protected function setSorting(ItemsEvent $event)
7966
}
8067

8168
/**
82-
* @param string $sortField
8369
* @param array<string, mixed> $options
8470
*
8571
* @return array<string, mixed>
8672
*/
87-
protected function getSort($sortField, array $options = [])
73+
protected function getSort(string $sortField, array $options = []): array
8874
{
8975
$sort = [
9076
'order' => $this->getSortDirection($sortField, $options),
@@ -112,12 +98,9 @@ protected function getSort($sortField, array $options = [])
11298
}
11399

114100
/**
115-
* @param string $sortField
116101
* @param array<string, mixed> $options
117-
*
118-
* @return string
119102
*/
120-
protected function getSortDirection($sortField, array $options = [])
103+
protected function getSortDirection(string $sortField, array $options = []): string
121104
{
122105
$dir = 'asc';
123106
$sortDirection = $this->getFromRequest($options['sortDirectionParameterName']);
@@ -143,13 +126,10 @@ private function getRequest(): ?Request
143126
return $this->requestStack->getCurrentRequest();
144127
}
145128

146-
/**
147-
* @return mixed|null
148-
*/
149-
private function getFromRequest(?string $key)
129+
private function getFromRequest(?string $key): mixed
150130
{
151131
if (null !== $key && null !== $request = $this->getRequest()) {
152-
return $request->get($key);
132+
return $request->query->get($key);
153133
}
154134

155135
return null;

0 commit comments

Comments
 (0)