Skip to content

Commit 0ea5374

Browse files
committed
Allow array values in search collections
1 parent 7ef2c9c commit 0ea5374

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

src/Repositories/AbstractSearchCollection.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,36 @@ public function filterBy(string $key, mixed $value): static
109109
$this->filterCollections[$filterClass] = new $filterClass($value);
110110
}
111111
elseif (is_array(static::$filterBy[$key])) {
112-
if ($value instanceof UuidInterface) {
113-
$value = $value->getBytes();
114-
}
115-
elseif ($value instanceof DefaultId) {
116-
$value = $value->toBytes();
117-
}
118112
$filter = (array)static::$filterBy[$key];
119113
$this->where[$key] = $filter;
120-
$this->where[$key][] = (string)$value;
114+
$this->where[$key][] = $this->castValue($value);
121115
}
122116
}
123117

124118
return $this;
125119
}
126120

121+
/**
122+
* @return string|array<int, mixed>
123+
*/
124+
protected function castValue(mixed $value): string|array
125+
{
126+
if (is_array($value)) {
127+
$values = [];
128+
foreach ($value as $item) {
129+
$values[] = $this->castValue($item);
130+
}
131+
return $values;
132+
}
133+
if ($value instanceof UuidInterface) {
134+
$value = $value->getBytes();
135+
}
136+
elseif ($value instanceof DefaultId) {
137+
$value = $value->toBytes();
138+
}
139+
return (string)$value;
140+
}
141+
127142
protected function handledFilterBy(string $key, mixed $value): bool
128143
{
129144
return false;

0 commit comments

Comments
 (0)