Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for comma separated numeric values in numeric filter #6719

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
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 numberic string (positive integer)' => [
[
'id' => null,
'name' => null,
'dummyPrice' => null,
],
[
'dummyPrice' => '21,22',
],
],
'multiple numeric string (positive integer)' => [
[
'id' => null,
Expand Down
Loading