Updating security samples for PHP client. (#5293)

This commit is contained in:
Paŭlo Ebermann
2017-04-04 08:42:01 +02:00
committed by wing328
parent cac803351b
commit 7462cf70cf
3 changed files with 44 additions and 30 deletions

View File

@@ -59,10 +59,16 @@ class ObjectSerializer
return $data;
} elseif (is_object($data)) {
$values = [];
foreach (array_keys($data::swaggerTypes()) as $property) {
foreach ($data::swaggerTypes() as $property => $swaggerType) {
$getter = $data::getters()[$property];
if ($data->$getter() !== null) {
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($data->$getter());
$value = $data->$getter();
if (method_exists($swaggerType, 'getAllowableEnumValues')
&& !in_array($value, $swaggerType::getAllowableEnumValues())) {
$imploded = implode("', '", $swaggerType::getAllowableEnumValues());
throw new \InvalidArgumentException("Invalid value for enum '$swaggerType', must be one of: '$imploded'");
}
if ($value !== null) {
$values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value);
}
}
return (object)$values;
@@ -269,6 +275,12 @@ class ObjectSerializer
}
return $deserialized;
} elseif (method_exists($class, 'getAllowableEnumValues')) {
if (!in_array($data, $class::getAllowableEnumValues())) {
$imploded = implode("', '", $class::getAllowableEnumValues());
throw new \InvalidArgumentException("Invalid value for enum '$class', must be one of: '$imploded'");
}
return $data;
} else {
// If a discriminator is defined and points to a valid subclass, use it.
$discriminator = $class::DISCRIMINATOR;