Skip to content

Commit f42a1c3

Browse files
authored
Add the ability to pass the data format
See #621
1 parent 0a9e748 commit f42a1c3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/main/resources/handlebars/php/ObjectSerializer.mustache

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,23 @@ class ObjectSerializer
109109
* later.
110110
*
111111
* @param string[]|string|\DateTime $object an object to be serialized to a string
112+
* @param string|null $format the format of the parameter
112113
*
113114
* @return string the serialized object
114115
*/
115-
public static function toQueryValue($object)
116+
public static function toQueryValue($object, $format = null)
116117
{
117118
if (is_array($object)) {
118119
return implode(',', $object);
119120
} else {
120-
return self::toString($object);
121+
return self::toString($object, $format);
121122
}
122123
}
123124

124125
/**
125126
* Take value and turn it into a string suitable for inclusion in
126127
* the header. If it's a string, pass through unchanged
127-
* If it's a datetime object, format it in ISO8601
128+
* If it's a datetime object, format it in RFC3339
128129
*
129130
* @param string $value a string which will be part of the header
130131
*
@@ -138,7 +139,7 @@ class ObjectSerializer
138139
/**
139140
* Take value and turn it into a string suitable for inclusion in
140141
* the http body (form parameter). If it's a string, pass through unchanged
141-
* If it's a datetime object, format it in ISO8601
142+
* If it's a datetime object, format it in RFC3339
142143
*
143144
* @param string|\SplFileObject $value the value of the form parameter
144145
*
@@ -156,16 +157,18 @@ class ObjectSerializer
156157
/**
157158
* Take value and turn it into a string suitable for inclusion in
158159
* the parameter. If it's a string, pass through unchanged
159-
* If it's a datetime object, format it in ISO8601
160+
* If it's a datetime object, format it in RFC3339
161+
* If it's a date, format it in Y-m-d
160162
*
161163
* @param string|\DateTime $value the value of the parameter
164+
* @param string|null $format the format of the parameter
162165
*
163166
* @return string the header string
164167
*/
165-
public static function toString($value)
168+
public static function toString($value, $format = null)
166169
{
167-
if ($value instanceof \DateTime) { // datetime in ISO8601 format
168-
return $value->format(\DateTime::ATOM);
170+
if ($value instanceof \DateTime) {
171+
return ($format === 'date') ? $value->format('Y-m-d') : $value->format(\DateTime::ATOM);
169172
} else {
170173
return $value;
171174
}

0 commit comments

Comments
 (0)