Fix warning when optional attribute doesn't exist

When an attribute required is set to `false` and the attribute doesn't exist in the response, we get warning `undefined array key "attribute"` in the console, this update prevents that error
This commit is contained in:
Damodar Lohani 2024-07-14 11:31:02 +05:45 committed by GitHub
parent ae87033974
commit c0efc232ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -590,6 +590,10 @@ class Response extends SwooleResponse
}
}
if(!$data->isSet($key) && !$rule['required']) { // skip attribute in response if not required and values does not exist
continue;
}
if ($rule['array']) {
if (!is_array($data[$key])) {
throw new Exception($key . ' must be an array of type ' . $rule['type']);