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 $context Context options for the normalizer:
array|scalar
Overrides NormalizerInterface::normalize
public function normalize($object, $format = null, array $context = array()) {
$reflectionObject = new \ReflectionObject($object);
$reflectionMethods = $reflectionObject
->getMethods(\ReflectionMethod::IS_PUBLIC);
$attributes = array();
foreach ($reflectionMethods as $method) {
if ($this
->isGetMethod($method)) {
$attributeName = lcfirst(substr($method->name, 3));
if (in_array($attributeName, $this->ignoredAttributes)) {
continue;
}
$attributeValue = $method
->invoke($object);
if (array_key_exists($attributeName, $this->callbacks)) {
$attributeValue = call_user_func($this->callbacks[$attributeName], $attributeValue);
}
if (null !== $attributeValue && !is_scalar($attributeValue)) {
$attributeValue = $this->serializer
->normalize($attributeValue, $format);
}
$attributes[$attributeName] = $attributeValue;
}
}
return $attributes;
}