Skip to content

Commit 141bdc8

Browse files
authored
[Filter] Do not only allow string on multi select filter. (#356)
* Do not only allow string on multi select filter. * Apply php-cs-fixer changes * Add Validation. --------- Co-authored-by: martineiber <[email protected]>
1 parent 4d368a7 commit 141bdc8

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/Model/Search/Modifier/Filter/FieldType/MultiSelectFilter.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@
1414
namespace Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\FieldType;
1515

1616
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\SearchModifierInterface;
17-
use Pimcore\ValueObject\Collection\ArrayOfStrings;
17+
use ValueError;
1818

1919
final readonly class MultiSelectFilter implements SearchModifierInterface
2020
{
21-
private ArrayOfStrings $values;
22-
2321
public function __construct(
2422
private string $field,
25-
array $values,
23+
private array $values,
2624
private bool $enablePqlFieldNameResolution = true,
2725
) {
28-
$this->values = new ArrayOfStrings($values);
26+
$this->validate();
2927
}
3028

3129
public function getField(): string
@@ -35,11 +33,25 @@ public function getField(): string
3533

3634
public function getValues(): array
3735
{
38-
return $this->values->getValue();
36+
return $this->values;
3937
}
4038

4139
public function isPqlFieldNameResolutionEnabled(): bool
4240
{
4341
return $this->enablePqlFieldNameResolution;
4442
}
43+
44+
private function validate(): void
45+
{
46+
foreach ($this->values as $value) {
47+
if (!is_string($value) && !is_int($value) && !is_float($value)) {
48+
throw new ValueError(
49+
sprintf(
50+
'Provided array must contain only string, int or float values. (%s given)',
51+
gettype($value)
52+
),
53+
);
54+
}
55+
}
56+
}
4557
}

0 commit comments

Comments
 (0)