Skip to content

Commit 149fe24

Browse files
authored
fix(doctrine): throw exception if property is null for the doctrine filters (#7681)
1 parent 350390b commit 149fe24

7 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/Doctrine/Odm/Filter/ExactFilter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use ApiPlatform\Doctrine\Common\Filter\ManagerRegistryAwareTrait;
1818
use ApiPlatform\Doctrine\Common\Filter\OpenApiFilterTrait;
1919
use ApiPlatform\Metadata\BackwardCompatibleFilterDescriptionTrait;
20+
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
2021
use ApiPlatform\Metadata\OpenApiParameterFilterInterface;
2122
use ApiPlatform\Metadata\Operation;
2223
use Doctrine\ODM\MongoDB\Aggregation\Builder;
@@ -40,6 +41,11 @@ final class ExactFilter implements FilterInterface, OpenApiParameterFilterInterf
4041
public function apply(Builder $aggregationBuilder, string $resourceClass, ?Operation $operation = null, array &$context = []): void
4142
{
4243
$parameter = $context['parameter'];
44+
45+
if (null === $parameter->getProperty()) {
46+
throw new InvalidArgumentException(\sprintf('The filter parameter with key "%s" must specify a property. Please provide the property explicitly.', $parameter->getKey()));
47+
}
48+
4349
$property = $parameter->getProperty();
4450
$value = $parameter->getValue();
4551
$operator = $context['operator'] ?? 'addAnd';

src/Doctrine/Odm/Filter/IriFilter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use ApiPlatform\Doctrine\Common\Filter\ManagerRegistryAwareTrait;
1818
use ApiPlatform\Doctrine\Common\Filter\OpenApiFilterTrait;
1919
use ApiPlatform\Metadata\BackwardCompatibleFilterDescriptionTrait;
20+
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
2021
use ApiPlatform\Metadata\OpenApiParameterFilterInterface;
2122
use ApiPlatform\Metadata\Operation;
2223
use ApiPlatform\Metadata\ParameterProviderFilterInterface;
@@ -40,6 +41,11 @@ final class IriFilter implements FilterInterface, OpenApiParameterFilterInterfac
4041
public function apply(Builder $aggregationBuilder, string $resourceClass, ?Operation $operation = null, array &$context = []): void
4142
{
4243
$parameter = $context['parameter'];
44+
45+
if (null === $parameter->getProperty()) {
46+
throw new InvalidArgumentException(\sprintf('The filter parameter with key "%s" must specify a property. Please provide the property explicitly.', $parameter->getKey()));
47+
}
48+
4349
$value = $parameter->getValue();
4450
$operator = $context['operator'] ?? 'addAnd';
4551
$match = $context['match'] = $context['match'] ??

src/Doctrine/Odm/Filter/PartialSearchFilter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\Doctrine\Common\Filter\OpenApiFilterTrait;
1717
use ApiPlatform\Metadata\BackwardCompatibleFilterDescriptionTrait;
18+
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
1819
use ApiPlatform\Metadata\OpenApiParameterFilterInterface;
1920
use ApiPlatform\Metadata\Operation;
2021
use Doctrine\ODM\MongoDB\Aggregation\Builder;
@@ -31,6 +32,11 @@ final class PartialSearchFilter implements FilterInterface, OpenApiParameterFilt
3132
public function apply(Builder $aggregationBuilder, string $resourceClass, ?Operation $operation = null, array &$context = []): void
3233
{
3334
$parameter = $context['parameter'];
35+
36+
if (null === $parameter->getProperty()) {
37+
throw new InvalidArgumentException(\sprintf('The filter parameter with key "%s" must specify a property. Please provide the property explicitly.', $parameter->getKey()));
38+
}
39+
3440
$property = $parameter->getProperty();
3541
$values = $parameter->getValue();
3642
$match = $context['match'] = $context['match'] ??

src/Doctrine/Orm/Filter/AbstractUuidFilter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $q
5959
return;
6060
}
6161

62+
if (null === $parameter->getProperty()) {
63+
throw new InvalidArgumentException(\sprintf('The filter parameter with key "%s" must specify a property. Nested properties are not automatically resolved. Please provide the property explicitly.', $parameter->getKey()));
64+
}
65+
6266
$this->filterProperty($parameter->getProperty(), $parameter->getValue(), $queryBuilder, $queryNameGenerator, $resourceClass, $operation, $context);
6367
}
6468

src/Doctrine/Orm/Filter/ExactFilter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Doctrine\Common\Filter\OpenApiFilterTrait;
1717
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
1818
use ApiPlatform\Metadata\BackwardCompatibleFilterDescriptionTrait;
19+
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
1920
use ApiPlatform\Metadata\OpenApiParameterFilterInterface;
2021
use ApiPlatform\Metadata\Operation;
2122
use Doctrine\ORM\QueryBuilder;
@@ -32,6 +33,11 @@ public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $q
3233
{
3334
$parameter = $context['parameter'];
3435
$value = $parameter->getValue();
36+
37+
if (null === $parameter->getProperty()) {
38+
throw new InvalidArgumentException(\sprintf('The filter parameter with key "%s" must specify a property. Please provide the property explicitly.', $parameter->getKey()));
39+
}
40+
3541
$property = $parameter->getProperty();
3642
$alias = $queryBuilder->getRootAliases()[0];
3743
$parameterName = $queryNameGenerator->generateParameterName($property);

src/Doctrine/Orm/Filter/IriFilter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Doctrine\Common\Filter\OpenApiFilterTrait;
1717
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
1818
use ApiPlatform\Metadata\BackwardCompatibleFilterDescriptionTrait;
19+
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
1920
use ApiPlatform\Metadata\OpenApiParameterFilterInterface;
2021
use ApiPlatform\Metadata\Operation;
2122
use ApiPlatform\Metadata\ParameterProviderFilterInterface;
@@ -34,6 +35,11 @@ public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $q
3435
{
3536
$parameter = $context['parameter'];
3637
$value = $parameter->getValue();
38+
39+
if (null === $parameter->getProperty()) {
40+
throw new InvalidArgumentException(\sprintf('The filter parameter with key "%s" must specify a property. Please provide the property explicitly.', $parameter->getKey()));
41+
}
42+
3743
$property = $parameter->getProperty();
3844
$alias = $queryBuilder->getRootAliases()[0];
3945
$parameterName = $queryNameGenerator->generateParameterName($property);

src/Doctrine/Orm/Filter/PartialSearchFilter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Doctrine\Common\Filter\OpenApiFilterTrait;
1717
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
1818
use ApiPlatform\Metadata\BackwardCompatibleFilterDescriptionTrait;
19+
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
1920
use ApiPlatform\Metadata\OpenApiParameterFilterInterface;
2021
use ApiPlatform\Metadata\Operation;
2122
use Doctrine\ORM\QueryBuilder;
@@ -31,6 +32,11 @@ final class PartialSearchFilter implements FilterInterface, OpenApiParameterFilt
3132
public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
3233
{
3334
$parameter = $context['parameter'];
35+
36+
if (null === $parameter->getProperty()) {
37+
throw new InvalidArgumentException(\sprintf('The filter parameter with key "%s" must specify a property. Please provide the property explicitly.', $parameter->getKey()));
38+
}
39+
3440
$property = $parameter->getProperty();
3541
$alias = $queryBuilder->getRootAliases()[0];
3642
$field = $alias.'.'.$property;

0 commit comments

Comments
 (0)