[PHP] Fix enum validation in container setters

When the setter is taking an array as argument we cannot use
`in_array()` to validate if the values are part of the allowed enum
values. Instead we use `array_diff()` for containers now.
This commit is contained in:
Arne Jørgensen 2016-08-05 10:35:11 +02:00
parent b74c1b98a2
commit 03c7e3ea0b

View File

@ -238,9 +238,16 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
{
{{#isEnum}}
$allowed_values = array({{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}});
{{^isContainer}}
if (!in_array(${{{name}}}, $allowed_values)) {
throw new \InvalidArgumentException("Invalid value for '{{name}}', must be one of {{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}");
}
{{/isContainer}}
{{#isContainer}}
if (array_diff(${{{name}}}, $allowed_values)) {
throw new \InvalidArgumentException("Invalid value for '{{name}}', must be one of {{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}");
}
{{/isContainer}}
{{/isEnum}}
{{#hasValidation}}
{{#maxLength}}