FIX Normalise casing before casting fields

This commit is contained in:
Guy Sartorelli 2022-08-25 17:36:06 +12:00
parent a7c8ce8d0c
commit 6d885ab894
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A
1 changed files with 6 additions and 3 deletions

View File

@ -319,9 +319,12 @@ class ViewableData implements IteratorAggregate
*/
public function castingHelper($field)
{
$specs = static::config()->get('casting');
if (isset($specs[$field])) {
return $specs[$field];
// Get casting if it has been configured.
// DB fields and PHP methods are all case insensitive so we normalise casing before checking.
$specs = array_change_key_case(static::config()->get('casting'), CASE_LOWER);
$fieldLower = strtolower($field);
if (isset($specs[$fieldLower])) {
return $specs[$fieldLower];
}
// If no specific cast is declared, fall back to failover.