Normalizes an object into a set of arrays/scalars
object $object object to normalize:
string $format format the normalization result will be encoded as:
array|scalar
Overrides NormalizerInterface::normalize
public function normalize($data, $format = null) {
if (null === $data || is_scalar($data)) {
return $data;
}
if (is_object($data) && $this
->supportsNormalization($data, $format)) {
return $this
->normalizeObject($data, $format);
}
if ($data instanceof \Traversable) {
$normalized = array();
foreach ($data as $key => $val) {
$normalized[$key] = $this
->normalize($val, $format);
}
return $normalized;
}
if (is_object($data)) {
return $this
->normalizeObject($data, $format);
}
if (is_array($data)) {
foreach ($data as $key => $val) {
$data[$key] = $this
->normalize($val, $format);
}
return $data;
}
throw new UnexpectedValueException('An unexpected value could not be normalized: ' . var_export($data, true));
}