Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dcc2204

Browse files
Merge pull request #428 from alexhampu/master
add enum processing when fetching values from where statements
2 parents 48db425 + f78d819 commit dcc2204

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

‎src/CacheKey.php‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,22 +280,18 @@ protected function getValuesFromWhere(array $where) : string
280280
}
281281

282282
if (is_array((new Arr)->get($where, "values"))) {
283-
return implode("_", collect($where["values"])->flatten()->toArray());
283+
$values = collect($where["values"])->flatten()->toArray();
284+
return implode("_", $this->processEnums($values));
284285
}
285286

286287
if (is_array((new Arr)->get($where, "value"))) {
287-
return implode("_", collect($where["value"])->flatten()->toArray());
288+
$values = collect($where["value"])->flatten()->toArray();
289+
return implode("_", $this->processEnums($values));
288290
}
289291

290292
$value = (new Arr)->get($where, "value", "");
291293

292-
if ($value instanceof \BackedEnum) {
293-
return $value->value;
294-
} elseif ($value instanceof \UnitEnum) {
295-
return $value->name;
296-
}
297-
298-
return $value;
294+
return $this->processEnum($value);
299295
}
300296

301297
protected function getValuesFromBindings(array $where, string $values) : string
@@ -396,4 +392,20 @@ protected function recursiveImplode(array $items, string $glue = ",") : string
396392

397393
return $result;
398394
}
395+
396+
private function processEnum(\BackedEnum|\UnitEnum|string $value): string
397+
{
398+
if ($value instanceof \BackedEnum) {
399+
return $value->value;
400+
} elseif ($value instanceof \UnitEnum) {
401+
return $value->name;
402+
}
403+
404+
return $value;
405+
}
406+
407+
private function processEnums(array $values): array
408+
{
409+
return array_map(fn($value) => $this->processEnum($value), $values);
410+
}
399411
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /