11<?php
2+
23/**
34 * ObjectSerializer
45 *
3031namespace OpenAPI \Client ;
3132
3233use GuzzleHttp \Psr7 \Utils ;
34+ use OpenAPI \Client \Model \CustomizableModelAbstract ;
3335use OpenAPI \Client \Model \ModelInterface ;
3436
3537/**
@@ -64,7 +66,7 @@ public static function setDateTimeFormat($format)
6466 *
6567 * @return scalar|object|array|null serialized form of $data
6668 */
67- public static function sanitizeForSerialization ($ data , $ type = null , $ format = null )
69+ public static function sanitizeForSerialization ($ data , $ type = null , $ format = null , bool $ root = true )
6870 {
6971 if (is_scalar ($ data ) || null === $ data ) {
7072 return $ data ;
@@ -76,7 +78,7 @@ public static function sanitizeForSerialization($data, $type = null, $format = n
7678
7779 if (is_array ($ data )) {
7880 foreach ($ data as $ property => $ value ) {
79- $ data [$ property ] = self ::sanitizeForSerialization ($ value );
81+ $ data [$ property ] = self ::sanitizeForSerialization (data: $ value, root: false );
8082 }
8183 return $ data ;
8284 }
@@ -100,20 +102,53 @@ public static function sanitizeForSerialization($data, $type = null, $format = n
100102 }
101103 }
102104 if (($ data ::isNullable ($ property ) && $ data ->isNullableSetToNull ($ property )) || $ value !== null ) {
103- $ values [$ data ::attributeMap ()[$ property ]] = self ::sanitizeForSerialization ($ value , $ openAPIType , $ formats [$ property ]);
105+ $ values [$ data ::attributeMap ()[$ property ]] = self ::sanitizeForSerialization (data: $ value , type: $ openAPIType , format: $ formats [$ property ], root: false );
106+ }
107+ }
108+ if ($ root ) {
109+ if (is_subclass_of ($ data , CustomizableModelAbstract::class)) {
110+ $ customFields = $ data ->getCustomizableFields ();
111+ if (!empty ($ customFields )) {
112+ $ originalValues = $ values ;
113+ $ customFields = self ::dotNotationToNestedArray ($ customFields );
114+ $ values = array_merge_recursive ($ originalValues , $ customFields );
115+ }
104116 }
105117 }
106118 } else {
107- foreach ($ data as $ property => $ value ) {
108- $ values [$ property ] = self ::sanitizeForSerialization ($ value );
119+ foreach ($ data as $ property => $ value ) {
120+ $ values [$ property ] = self ::sanitizeForSerialization (data: $ value, root: false );
109121 }
110122 }
123+
111124 return (object )$ values ;
112125 } else {
113126 return (string )$ data ;
114127 }
115128 }
116129
130+ /**
131+ *
132+ * @param array $dotNotationArray
133+ * @return mixed
134+ */
135+ private static function dotNotationToNestedArray (array $ dotNotationArray )
136+ {
137+ $ nestedArray = [];
138+ foreach ($ dotNotationArray as $ key => $ value ) {
139+ $ parts = explode ('. ' , $ key );
140+ $ pointer = &$ nestedArray ;
141+ foreach ($ parts as $ part ) {
142+ if (!isset ($ pointer [$ part ])) {
143+ $ pointer [$ part ] = [];
144+ }
145+ $ pointer = &$ pointer [$ part ];
146+ }
147+ $ pointer = $ value ;
148+ }
149+ return $ nestedArray ;
150+ }
151+
117152 /**
118153 * Sanitize filename by removing path.
119154 * e.g. ../../sun.gif becomes sun.gif
@@ -140,7 +175,9 @@ public static function sanitizeFilename($filename)
140175 */
141176 public static function sanitizeTimestamp ($ timestamp )
142177 {
143- if (!is_string ($ timestamp )) return $ timestamp ;
178+ if (!is_string ($ timestamp )) {
179+ return $ timestamp ;
180+ }
144181
145182 return preg_replace ('/(:\d{2}.\d{6})\d*/ ' , '$1 ' , $ timestamp );
146183 }
@@ -236,7 +273,7 @@ public static function toQueryValue(
236273 }
237274
238275 # Handle DateTime objects in query
239- if ($ openApiType === "\\DateTime " && $ value instanceof \DateTime) {
276+ if ($ openApiType === "\\DateTime " && $ value instanceof \DateTime) {
240277 return ["{$ paramName }" => $ value ->format (self ::$ dateTimeFormat )];
241278 }
242279
@@ -246,7 +283,9 @@ public static function toQueryValue(
246283 // since \GuzzleHttp\Psr7\Query::build fails with nested arrays
247284 // need to flatten array first
248285 $ flattenArray = function ($ arr , $ name , &$ result = []) use (&$ flattenArray , $ style , $ explode ) {
249- if (!is_array ($ arr )) return $ arr ;
286+ if (!is_array ($ arr )) {
287+ return $ arr ;
288+ }
250289
251290 foreach ($ arr as $ k => $ v ) {
252291 $ prop = ($ style === 'deepObject ' ) ? $ prop = "{$ name }[ {$ k }] " : $ k ;
@@ -474,7 +513,7 @@ public static function deserialize($data, $class, $httpHeaders = null)
474513 // determine file name
475514 if (
476515 is_array ($ httpHeaders )
477- && array_key_exists ('Content-Disposition ' , $ httpHeaders )
516+ && array_key_exists ('Content-Disposition ' , $ httpHeaders )
478517 && preg_match ('/inline; filename=[ \'"]?([^ \'"\s]+)[ \'"]?$/i ' , $ httpHeaders ['Content-Disposition ' ], $ match )
479518 ) {
480519 $ filename = Configuration::getDefaultConfiguration ()->getTempFolderPath () . DIRECTORY_SEPARATOR . self ::sanitizeFilename ($ match [1 ]);
0 commit comments