Merge pull request #10470 from creative-commoners/pulls/4.11/case-insensitive-casting

FIX Normalise casing before casting fields
This commit is contained in:
Guy Sartorelli 2022-09-08 12:45:09 +12:00 committed by GitHub
commit 7e9ced0824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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.