[Serializer] Removed properties argument
This commit is contained in:
parent
49008b60c6
commit
9311b0a7e5
@ -130,6 +130,7 @@ beta1 to beta2
|
||||
* Serializer: `AbstractEncoder` & `AbstractNormalizer` were renamed to
|
||||
`SerializerAwareEncoder` & `SerializerAwareNormalizer`.
|
||||
|
||||
* Serializer: The `$properties` argument has been dropped from all interfaces.
|
||||
PR12 to beta1
|
||||
-------------
|
||||
|
||||
|
@ -21,9 +21,9 @@ class CustomNormalizer implements NormalizerInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format, $properties = null)
|
||||
public function normalize($object, $format)
|
||||
{
|
||||
return $object->normalize($this, $format, $properties);
|
||||
return $object->normalize($this, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,10 +38,8 @@ class GetSetMethodNormalizer extends SerializerAwareNormalizer
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format, $properties = null)
|
||||
public function normalize($object, $format)
|
||||
{
|
||||
$propertyMap = (null === $properties) ? null : array_flip(array_map('strtolower', $properties));
|
||||
|
||||
$reflectionObject = new \ReflectionObject($object);
|
||||
$reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC);
|
||||
|
||||
@ -50,14 +48,12 @@ class GetSetMethodNormalizer extends SerializerAwareNormalizer
|
||||
if ($this->isGetMethod($method)) {
|
||||
$attributeName = strtolower(substr($method->getName(), 3));
|
||||
|
||||
if (null === $propertyMap || isset($propertyMap[$attributeName])) {
|
||||
$attributeValue = $method->invoke($object);
|
||||
if (null !== $attributeValue && !is_scalar($attributeValue)) {
|
||||
$attributeValue = $this->serializer->normalize($attributeValue, $format);
|
||||
}
|
||||
|
||||
$attributes[$attributeName] = $attributeValue;
|
||||
$attributeValue = $method->invoke($object);
|
||||
if (null !== $attributeValue && !is_scalar($attributeValue)) {
|
||||
$attributeValue = $this->serializer->normalize($attributeValue, $format);
|
||||
}
|
||||
|
||||
$attributes[$attributeName] = $attributeValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,11 +32,9 @@ interface NormalizableInterface
|
||||
* grabbing the serializer from it to access other normalizers.
|
||||
* @param string|null $format The format is optionally given to be able to normalize differently
|
||||
* based on different output formats.
|
||||
* @param array|null $properties If provided, this is a (subset) list of
|
||||
* properties that should be exported from the object.
|
||||
* @return array|scalar
|
||||
*/
|
||||
function normalize(NormalizerInterface $normalizer, $format, $properties = null);
|
||||
function normalize(NormalizerInterface $normalizer, $format);
|
||||
|
||||
/**
|
||||
* Denormalizes the object back from an array of scalars|arrays.
|
||||
|
@ -25,11 +25,10 @@ interface NormalizerInterface
|
||||
*
|
||||
* @param object $object object to normalize
|
||||
* @param string $format format the normalization result will be encoded as
|
||||
* @param array $properties a list of properties to extract, if null all properties are returned
|
||||
* @return array|scalar
|
||||
* @api
|
||||
*/
|
||||
function normalize($object, $format, $properties = null);
|
||||
function normalize($object, $format);
|
||||
|
||||
/**
|
||||
* Denormalizes data back into an object of the given class
|
||||
|
@ -59,19 +59,19 @@ class Serializer implements SerializerInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalizeObject($object, $format, $properties = null)
|
||||
public function normalizeObject($object, $format)
|
||||
{
|
||||
if (!$this->normalizers) {
|
||||
throw new \LogicException('You must register at least one normalizer to be able to normalize objects.');
|
||||
}
|
||||
$class = get_class($object);
|
||||
if (isset($this->normalizerCache[$class][$format])) {
|
||||
return $this->normalizerCache[$class][$format]->normalize($object, $format, $properties);
|
||||
return $this->normalizerCache[$class][$format]->normalize($object, $format);
|
||||
}
|
||||
foreach ($this->normalizers as $normalizer) {
|
||||
if ($normalizer->supportsNormalization($object, $class, $format)) {
|
||||
$this->normalizerCache[$class][$format] = $normalizer;
|
||||
return $normalizer->normalize($object, $format, $properties);
|
||||
return $normalizer->normalize($object, $format);
|
||||
}
|
||||
}
|
||||
throw new \UnexpectedValueException('Could not normalize object of type '.$class.', no supporting normalizer found.');
|
||||
|
Reference in New Issue
Block a user