From 9311b0a7e50c5139394904e099e3b8b50feaa77f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 8 May 2011 18:32:22 +0200 Subject: [PATCH] [Serializer] Removed properties argument --- UPDATE.md | 1 + .../Serializer/Normalizer/CustomNormalizer.php | 4 ++-- .../Normalizer/GetSetMethodNormalizer.php | 16 ++++++---------- .../Normalizer/NormalizableInterface.php | 4 +--- .../Normalizer/NormalizerInterface.php | 3 +-- src/Symfony/Component/Serializer/Serializer.php | 6 +++--- 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/UPDATE.md b/UPDATE.md index 101450b18f..d63ae53fb1 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -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 ------------- diff --git a/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php index 2f1fd53977..20aef55482 100644 --- a/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php @@ -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); } /** diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index 7829308392..bdf7c4e092 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -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; } } diff --git a/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php b/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php index 7e5ef795ae..5b9c644753 100644 --- a/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php @@ -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. diff --git a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php index 32578390a2..20fb7b51ec 100644 --- a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php @@ -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 diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index 9338831486..d48622c3e4 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -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.');