From 5a1f08491021f363875296a71212d90795653197 Mon Sep 17 00:00:00 2001 From: Teoh Han Hui Date: Wed, 9 May 2018 14:44:34 +0200 Subject: [PATCH] [Serializer] Rename CacheableSupportsMethodInterface to VaryingSupportInterface --- src/Symfony/Component/Serializer/CHANGELOG.md | 2 +- .../Serializer/Normalizer/AbstractNormalizer.php | 6 +++--- .../Serializer/Normalizer/ArrayDenormalizer.php | 6 +++--- .../ConstraintViolationListNormalizer.php | 6 +++--- .../Serializer/Normalizer/CustomNormalizer.php | 6 +++--- .../Serializer/Normalizer/DataUriNormalizer.php | 6 +++--- .../Normalizer/DateIntervalNormalizer.php | 6 +++--- .../Serializer/Normalizer/DateTimeNormalizer.php | 6 +++--- .../Normalizer/GetSetMethodNormalizer.php | 4 ++-- .../Normalizer/JsonSerializableNormalizer.php | 4 ++-- .../Serializer/Normalizer/ObjectNormalizer.php | 4 ++-- .../Serializer/Normalizer/PropertyNormalizer.php | 4 ++-- ...dInterface.php => VaryingSupportInterface.php} | 15 ++++++++------- src/Symfony/Component/Serializer/Serializer.php | 6 +++--- 14 files changed, 41 insertions(+), 40 deletions(-) rename src/Symfony/Component/Serializer/Normalizer/{CacheableSupportsMethodInterface.php => VaryingSupportInterface.php} (50%) diff --git a/src/Symfony/Component/Serializer/CHANGELOG.md b/src/Symfony/Component/Serializer/CHANGELOG.md index 983bb9f5a0654..cee9b75daea71 100644 --- a/src/Symfony/Component/Serializer/CHANGELOG.md +++ b/src/Symfony/Component/Serializer/CHANGELOG.md @@ -4,7 +4,7 @@ CHANGELOG 4.1.0 ----- -* added `CacheableSupportsMethodInterface` for normalizers and denormalizers that use +* added `VaryingSupportInterface` for normalizers and denormalizers that use only the type and the format in their `supports*()` methods * added `MissingConstructorArgumentsException` new exception for deserialization failure of objects that needs data insertion in constructor diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php index eb66d6540d60b..58dbfc35f00b8 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php @@ -27,7 +27,7 @@ * * @author Kévin Dunglas */ -abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface, CacheableSupportsMethodInterface +abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface, VaryingSupportInterface { use ObjectToPopulateTrait; use SerializerAwareTrait; @@ -150,9 +150,9 @@ public function setIgnoredAttributes(array $ignoredAttributes) /** * {@inheritdoc} */ - public function hasCacheableSupportsMethod(): bool + public function isSupportVariedOnDataAndContext(): bool { - return false; + return true; } /** diff --git a/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php index a52b24c31e878..b4033c4e05ad2 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php @@ -24,7 +24,7 @@ * * @final */ -class ArrayDenormalizer implements ContextAwareDenormalizerInterface, SerializerAwareInterface, CacheableSupportsMethodInterface +class ArrayDenormalizer implements ContextAwareDenormalizerInterface, SerializerAwareInterface, VaryingSupportInterface { /** * @var SerializerInterface|DenormalizerInterface @@ -87,8 +87,8 @@ public function setSerializer(SerializerInterface $serializer) /** * {@inheritdoc} */ - public function hasCacheableSupportsMethod(): bool + public function isSupportVariedOnDataAndContext(): bool { - return $this->serializer instanceof CacheableSupportsMethodInterface && $this->serializer->hasCacheableSupportsMethod(); + return !$this->serializer instanceof VaryingSupportInterface || $this->serializer->isSupportVariedOnDataAndContext(); } } diff --git a/src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php index 2ba258ecb7271..c69b4175640c1 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php @@ -22,7 +22,7 @@ * @author Grégoire Pineau * @author Kévin Dunglas */ -class ConstraintViolationListNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface +class ConstraintViolationListNormalizer implements NormalizerInterface, VaryingSupportInterface { /** * {@inheritdoc} @@ -60,8 +60,8 @@ public function supportsNormalization($data, $format = null) /** * {@inheritdoc} */ - public function hasCacheableSupportsMethod(): bool + public function isSupportVariedOnDataAndContext(): bool { - return __CLASS__ === \get_class($this); + return __CLASS__ !== \get_class($this); } } diff --git a/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php index 695318a5bcf56..7ddd8aa64f2b4 100644 --- a/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php @@ -17,7 +17,7 @@ /** * @author Jordi Boggiano */ -class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface, CacheableSupportsMethodInterface +class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface, VaryingSupportInterface { use ObjectToPopulateTrait; use SerializerAwareTrait; @@ -71,8 +71,8 @@ public function supportsDenormalization($data, $type, $format = null) /** * {@inheritdoc} */ - public function hasCacheableSupportsMethod(): bool + public function isSupportVariedOnDataAndContext(): bool { - return __CLASS__ === \get_class($this); + return __CLASS__ !== \get_class($this); } } diff --git a/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php index 82b5c8bdde68e..81d6e0c201615 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php @@ -23,7 +23,7 @@ * * @author Kévin Dunglas */ -class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, CacheableSupportsMethodInterface +class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, VaryingSupportInterface { private static $supportedTypes = array( \SplFileInfo::class => true, @@ -122,9 +122,9 @@ public function supportsDenormalization($data, $type, $format = null) /** * {@inheritdoc} */ - public function hasCacheableSupportsMethod(): bool + public function isSupportVariedOnDataAndContext(): bool { - return __CLASS__ === \get_class($this); + return __CLASS__ !== \get_class($this); } /** diff --git a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php index 6fdf8b4a8af30..c3795f081fca5 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php @@ -20,7 +20,7 @@ * * @author Jérôme Parmentier */ -class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterface, CacheableSupportsMethodInterface +class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterface, VaryingSupportInterface { const FORMAT_KEY = 'dateinterval_format'; @@ -58,9 +58,9 @@ public function supportsNormalization($data, $format = null) /** * {@inheritdoc} */ - public function hasCacheableSupportsMethod(): bool + public function isSupportVariedOnDataAndContext(): bool { - return __CLASS__ === \get_class($this); + return __CLASS__ !== \get_class($this); } /** diff --git a/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php index b2ebe97bd57e9..cc17be28f98a9 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php @@ -20,7 +20,7 @@ * * @author Kévin Dunglas */ -class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface, CacheableSupportsMethodInterface +class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface, VaryingSupportInterface { const FORMAT_KEY = 'datetime_format'; const TIMEZONE_KEY = 'datetime_timezone'; @@ -119,9 +119,9 @@ public function supportsDenormalization($data, $type, $format = null) /** * {@inheritdoc} */ - public function hasCacheableSupportsMethod(): bool + public function isSupportVariedOnDataAndContext(): bool { - return __CLASS__ === \get_class($this); + return __CLASS__ !== \get_class($this); } /** diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index 0bf719771a977..d54faacd28fd8 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -55,9 +55,9 @@ public function supportsDenormalization($data, $type, $format = null) /** * {@inheritdoc} */ - public function hasCacheableSupportsMethod(): bool + public function isSupportVariedOnDataAndContext(): bool { - return __CLASS__ === \get_class($this); + return __CLASS__ !== \get_class($this); } /** diff --git a/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php index 15d0da1aadef6..f9ece930e2c1e 100644 --- a/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php @@ -68,8 +68,8 @@ public function denormalize($data, $class, $format = null, array $context = arra /** * {@inheritdoc} */ - public function hasCacheableSupportsMethod(): bool + public function isSupportVariedOnDataAndContext(): bool { - return __CLASS__ === \get_class($this); + return __CLASS__ !== \get_class($this); } } diff --git a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php index bf463fe5457d3..f3dfbf09003ec 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php @@ -43,9 +43,9 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory /** * {@inheritdoc} */ - public function hasCacheableSupportsMethod(): bool + public function isSupportVariedOnDataAndContext(): bool { - return __CLASS__ === \get_class($this); + return __CLASS__ !== \get_class($this); } /** diff --git a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php index a2207c636ffd3..bf89eab85737f 100644 --- a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php @@ -49,9 +49,9 @@ public function supportsDenormalization($data, $type, $format = null) /** * {@inheritdoc} */ - public function hasCacheableSupportsMethod(): bool + public function isSupportVariedOnDataAndContext(): bool { - return __CLASS__ === \get_class($this); + return __CLASS__ !== \get_class($this); } /** diff --git a/src/Symfony/Component/Serializer/Normalizer/CacheableSupportsMethodInterface.php b/src/Symfony/Component/Serializer/Normalizer/VaryingSupportInterface.php similarity index 50% rename from src/Symfony/Component/Serializer/Normalizer/CacheableSupportsMethodInterface.php rename to src/Symfony/Component/Serializer/Normalizer/VaryingSupportInterface.php index 3a55f653b1786..9ac20312f201c 100644 --- a/src/Symfony/Component/Serializer/Normalizer/CacheableSupportsMethodInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/VaryingSupportInterface.php @@ -12,15 +12,16 @@ namespace Symfony\Component\Serializer\Normalizer; /** - * Marker interface for normalizers and denormalizers that use - * only the type and the format in their supports*() methods. - * - * By implementing this interface, the return value of the - * supports*() methods will be cached by type and format. + * Defines the criteria by which normalizers and denormalizers may vary + * their support. * * @author Kévin Dunglas */ -interface CacheableSupportsMethodInterface +interface VaryingSupportInterface { - public function hasCacheableSupportsMethod(): bool; + /** + * Checks whether the normalization and denormalization support + * will vary depending on the data and context provided. + */ + public function isSupportVariedOnDataAndContext(): bool; } diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index bcd1bfb80b58b..63ef8eaa30cbd 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -19,13 +19,13 @@ use Symfony\Component\Serializer\Encoder\DecoderInterface; use Symfony\Component\Serializer\Exception\NotEncodableValueException; use Symfony\Component\Serializer\Exception\NotNormalizableValueException; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\ContextAwareDenormalizerInterface; use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; +use Symfony\Component\Serializer\Normalizer\VaryingSupportInterface; use Symfony\Component\Serializer\Exception\LogicException; /** @@ -221,7 +221,7 @@ private function getNormalizer($data, ?string $format, array $context) continue; } - if (!$normalizer instanceof CacheableSupportsMethodInterface || !$normalizer->hasCacheableSupportsMethod()) { + if (!$normalizer instanceof VaryingSupportInterface || $normalizer->isSupportVariedOnDataAndContext()) { $this->normalizerCache[$format][$type][$k] = false; } elseif ($normalizer->supportsNormalization($data, $format)) { $this->normalizerCache[$format][$type][$k] = true; @@ -262,7 +262,7 @@ private function getDenormalizer($data, string $class, ?string $format, array $c continue; } - if (!$normalizer instanceof CacheableSupportsMethodInterface || !$normalizer->hasCacheableSupportsMethod()) { + if (!$normalizer instanceof VaryingSupportInterface || $normalizer->isSupportVariedOnDataAndContext()) { $this->denormalizerCache[$format][$class][$k] = false; } elseif ($normalizer->supportsDenormalization(null, $class, $format)) { $this->denormalizerCache[$format][$class][$k] = true;