@@ -127,27 +127,24 @@ public function normalize($data, $format = null, array $context = array())
127
127
if (null === $ data || is_scalar ($ data )) {
128
128
return $ data ;
129
129
}
130
- if (is_object ($ data ) && $ this ->supportsNormalization ($ data , $ format )) {
131
- return $ this ->normalizeObject ($ data , $ format , $ context );
132
- }
133
- if ($ data instanceof \Traversable) {
130
+
131
+ if (is_array ($ data ) || $ data instanceof \Traversable) {
134
132
$ normalized = array ();
135
133
foreach ($ data as $ key => $ val ) {
136
134
$ normalized [$ key ] = $ this ->normalize ($ val , $ format , $ context );
137
135
}
138
136
139
137
return $ normalized ;
140
138
}
139
+
141
140
if (is_object ($ data )) {
142
- return $ this ->normalizeObject ($ data , $ format , $ context );
143
- }
144
- if (is_array ($ data )) {
145
- foreach ($ data as $ key => $ val ) {
146
- $ data [$ key ] = $ this ->normalize ($ val , $ format , $ context );
141
+ if (!$ this ->normalizers ) {
142
+ throw new LogicException ('You must register at least one normalizer to be able to normalize objects. ' );
147
143
}
148
144
149
- return $ data ;
145
+ throw new UnexpectedValueException ( sprintf ( ' Could not normalize object of type %s, no supporting normalizer found. ' , get_class ( $ data))) ;
150
146
}
147
+
151
148
throw new UnexpectedValueException (sprintf ('An unexpected value could not be normalized: %s ' , var_export ($ data , true )));
152
149
}
153
150
@@ -230,31 +227,6 @@ final public function decode($data, $format, array $context = array())
230
227
return $ this ->decoder ->decode ($ data , $ format , $ context );
231
228
}
232
229
233
- /**
234
- * Normalizes an object into a set of arrays/scalars.
235
- *
236
- * @param object $object object to normalize
237
- * @param string $format format name, present to give the option to normalizers to act differently based on formats
238
- * @param array $context The context data for this particular normalization
239
- *
240
- * @return array|string|bool|int|float|null
241
- *
242
- * @throws LogicException
243
- * @throws UnexpectedValueException
244
- */
245
- private function normalizeObject ($ object , $ format , array $ context = array ())
246
- {
247
- if (!$ this ->normalizers ) {
248
- throw new LogicException ('You must register at least one normalizer to be able to normalize objects. ' );
249
- }
250
-
251
- if ($ normalizer = $ this ->getNormalizer ($ object , $ format )) {
252
- return $ normalizer ->normalize ($ object , $ format , $ context );
253
- }
254
-
255
- throw new UnexpectedValueException (sprintf ('Could not normalize object of type %s, no supporting normalizer found. ' , get_class ($ object )));
256
- }
257
-
258
230
/**
259
231
* Denormalizes data back into an object of the given class.
260
232
*
0 commit comments