adding static setters/getters for models since members are no public

This commit is contained in:
nmonterroso 2015-06-22 11:19:01 -07:00
parent 5de99bafa7
commit 109b7eeaec
2 changed files with 26 additions and 9 deletions

View File

@ -21,8 +21,9 @@ class ObjectSerializer {
} else if (is_object($data)) { } else if (is_object($data)) {
$values = array(); $values = array();
foreach (array_keys($data::$swaggerTypes) as $property) { foreach (array_keys($data::$swaggerTypes) as $property) {
if ($data->$property !== null) { $getter = $data::$getters[$property];
$values[$data::$attributeMap[$property]] = self::sanitizeForSerialization($data->$property); if ($data->$getter() !== null) {
$values[$data::$attributeMap[$property]] = self::sanitizeForSerialization($data->$getter());
} }
} }
$sanitized = $values; $sanitized = $values;
@ -131,9 +132,15 @@ class ObjectSerializer {
} else { } else {
$instance = new $class(); $instance = new $class();
foreach ($instance::$swaggerTypes as $property => $type) { foreach ($instance::$swaggerTypes as $property => $type) {
$original_property_name = $instance::$attributeMap[$property]; $propertySetter = $instance::$setters[$property];
if (isset($original_property_name) && isset($data->$original_property_name)) {
$instance->$property = self::deserialize($data->$original_property_name, $type); if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) {
continue;
}
$propertyValue = $data->{$instance::$attributeMap[$property]};
if (isset($propertyValue)) {
$instance->$propertySetter(self::deserialize($propertyValue, $type));
} }
} }
$deserialized = $instance; $deserialized = $instance;

View File

@ -39,6 +39,16 @@ class {{classname}} implements ArrayAccess {
{{/hasMore}}{{/vars}} {{/hasMore}}{{/vars}}
); );
static $setters = array(
{{#vars}}'{{name}}' => '{{setter}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
);
static $getters = array(
{{#vars}}'{{name}}' => '{{getter}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
);
{{#vars}} {{#vars}}
/**{{#description}} /**{{#description}}
* {{{description}}}{{/description}} * {{{description}}}{{/description}}