Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Doctrine/Common/Filter/NumericFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ protected function isNumericField(string $property, string $resourceClass): bool

protected function normalizeValues($value, string $property): ?array
{
// Allow CSV format for multiple values.
if (\is_string($value) && str_contains($value, ',')) {
$value = explode(',', $value);
}

if (!is_numeric($value) && (!\is_array($value) || !$this->isNumericArray($value))) {
$this->getLogger()->notice('Invalid filter ignored', [
'exception' => new InvalidArgumentException(\sprintf('Invalid numeric value for "%s" property', $property)),
Expand Down
3 changes: 3 additions & 0 deletions src/Doctrine/Orm/Tests/Filter/NumericFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public static function provideApplyTestData(): array
'numeric string (positive integer)' => [
\sprintf('SELECT o FROM %s o WHERE o.dummyPrice = :dummyPrice_p1', Dummy::class),
],
'comma-separated numeric string (positive integer)' => [
\sprintf('SELECT o FROM %s o WHERE o.dummyPrice IN (:dummyPrice_p1)', Dummy::class),
],
'multiple numeric string (positive integer)' => [
\sprintf('SELECT o FROM %s o WHERE o.dummyPrice IN (:dummyPrice_p1)', Dummy::class),
],
Expand Down
10 changes: 10 additions & 0 deletions src/Doctrine/Orm/Tests/Filter/NumericFilterTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ private static function provideApplyTestArguments(): array
'dummyPrice' => '21',
],
],
'comma-separated numeric string (positive integer)' => [
[
'id' => null,
'name' => null,
'dummyPrice' => null,
],
[
'dummyPrice' => ['21,22'],
],
],
'multiple numeric string (positive integer)' => [
[
'id' => null,
Expand Down
Loading