Skip to content

Commit e00db09

Browse files
committed
Make ParameterExtension context more generic
1 parent 6b89e4f commit e00db09

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/Doctrine/Odm/Extension/OrderExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected function getManagerRegistry(): ManagerRegistry
9797
private function hasSortStage(Builder $aggregationBuilder): bool
9898
{
9999
try {
100-
for ($index = 0; true; $index++) {
100+
for ($index = 0; true; ++$index) {
101101
if ($aggregationBuilder->getStage($index) instanceof Sort) {
102102
// If at least one stage is sort, then it has sorting
103103
return true;

src/Doctrine/Odm/Extension/ParameterExtension.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,10 @@ private function applyFilter(Builder $aggregationBuilder, ?string $resourceClass
8989
$filter->setProperties($properties ?? []);
9090
}
9191

92-
$filterContext = ['filters' => $values, 'parameter' => $parameter, 'match' => $context['match'] ?? null, 'search' => $context['search'] ?? null];
92+
$specificContext = ['filters' => $values, 'parameter' => $parameter];
93+
$filterContext = array_replace($context, $specificContext);
9394
$filter->apply($aggregationBuilder, $resourceClass, $operation, $filterContext);
94-
// update by reference
95-
if (isset($filterContext['mongodb_odm_sort_fields'])) {
96-
$context['mongodb_odm_sort_fields'] = $filterContext['mongodb_odm_sort_fields'];
97-
}
98-
if (isset($filterContext['match'])) {
99-
$context['match'] = $filterContext['match'];
100-
}
101-
if (isset($filterContext['search'])) {
102-
$context['search'] = $filterContext['search'];
103-
}
95+
$context = array_replace($context, array_diff_key($filterContext, $specificContext));
10496
}
10597

10698
if (isset($context['match'])) {

src/Doctrine/Odm/Filter/AtlasSearchFilter.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
declare(strict_types=1);
413

514
namespace ApiPlatform\Doctrine\Odm\Filter;
@@ -84,7 +93,7 @@ public function apply(Builder $aggregationBuilder, string $resourceClass, ?Opera
8493
->fuzzy(maxEdits: 1);
8594
break;
8695
default:
87-
throw new \InvalidArgumentException(sprintf('Unsupported operator "%s" for AtlasSearchFilter', $this->operator));
96+
throw new \InvalidArgumentException(\sprintf('Unsupported operator "%s" for AtlasSearchFilter', $this->operator));
8897
}
8998
}
9099
}

0 commit comments

Comments
 (0)