public static function sanitizeForSerialization()

in lib/Api/ObjectSerializer.php [36:70]


    public static function sanitizeForSerialization($data, $format = null)
    {
        if (is_bool($data)) {
            return self::serializeBool((bool)$data);
        } elseif (is_scalar($data) || null === $data) {
            return $data;
        } elseif ($data instanceof \DateTime) {
            return ($format === 'date') ? $data->format('Y-m-d') : $data->format('Y-m-dTH:i:sZ');
        } elseif (is_array($data)) {
            foreach ($data as $property => $value) {
                $data[$property] = self::sanitizeForSerialization($value);
            }
            return $data;
        } elseif (is_object($data)) {
            $values = [];
            $formats = $data::serialFormats();
            foreach ($data::serialTypes() as $property => $serialType) {
                $getter = $data::getters()[$property];
                $value = $data->$getter();
                if ($value !== null
                    && !in_array($serialType, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)
                    && method_exists($serialType, 'getAllowableEnumValues')
                    && !in_array($value, $serialType::getAllowableEnumValues())) {
                    $imploded = implode("', '", $serialType::getAllowableEnumValues());
                    throw new \InvalidArgumentException("Invalid value for enum '$serialType', must be one of: '$imploded'");
                }
                if ($value !== null) {
                    $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $serialType, $formats[$property]);
                }
            }
            return (object)$values;
        } else {
            return (string)$data;
        }
    }