Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] Add ->hasCacheableSupportsMethod() to CacheableSupportsMethodInterface #27105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Serializer] Add ->hasCacheableSupportsMethod() to CacheableSupportsM…
…ethodInterface
  • Loading branch information
nicolas-grekas committed May 1, 2018
commit 04b369215c0ee4a723fc4efb27c6565f681e93a2
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface
abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface, CacheableSupportsMethodInterface
{
use ObjectToPopulateTrait;
use SerializerAwareTrait;
Expand Down Expand Up @@ -147,6 +147,14 @@ public function setIgnoredAttributes(array $ignoredAttributes)
return $this;
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return false;
}

/**
* Detects if the configured circular reference limit is reached.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
abstract class AbstractObjectNormalizer extends AbstractNormalizer implements CacheableSupportsMethodInterface
abstract class AbstractObjectNormalizer extends AbstractNormalizer
{
const ENABLE_MAX_DEPTH = 'enable_max_depth';
const DEPTH_KEY_PATTERN = 'depth_%s::%s';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @final
*/
class ArrayDenormalizer implements ContextAwareDenormalizerInterface, SerializerAwareInterface
class ArrayDenormalizer implements ContextAwareDenormalizerInterface, SerializerAwareInterface, CacheableSupportsMethodInterface
{
/**
* @var SerializerInterface|DenormalizerInterface
Expand Down Expand Up @@ -83,4 +83,12 @@ public function setSerializer(SerializerInterface $serializer)

$this->serializer = $serializer;
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return $this->serializer instanceof CacheableSupportsMethodInterface && $this->serializer->hasCacheableSupportsMethod();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
*/
interface CacheableSupportsMethodInterface
{
public function hasCacheableSupportsMethod(): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,12 @@ public function supportsNormalization($data, $format = null)
{
return $data instanceof ConstraintViolationListInterface;
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return __CLASS__ === \get_class($this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,12 @@ public function supportsDenormalization($data, $type, $format = null)
{
return \is_subclass_of($type, DenormalizableInterface::class);
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return __CLASS__ === \get_class($this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ public function supportsDenormalization($data, $type, $format = null)
return isset(self::$supportedTypes[$type]);
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return __CLASS__ === \get_class($this);
}

/**
* Gets the mime type of the object. Defaults to application/octet-stream.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public function supportsNormalization($data, $format = null)
return $data instanceof \DateInterval;
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return __CLASS__ === \get_class($this);
}

/**
* {@inheritdoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ public function supportsDenormalization($data, $type, $format = null)
return isset(self::$supportedTypes[$type]);
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return __CLASS__ === \get_class($this);
}

/**
* Formats datetime errors.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public function supportsDenormalization($data, $type, $format = null)
return parent::supportsDenormalization($data, $type, $format) && $this->supports($type);
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return __CLASS__ === \get_class($this);
}

/**
* Checks if the given class has any get{Property} method.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @author Fred Cox <mcfedr@gmail.com>
*/
class JsonSerializableNormalizer extends AbstractNormalizer implements CacheableSupportsMethodInterface
class JsonSerializableNormalizer extends AbstractNormalizer
{
/**
* {@inheritdoc}
Expand Down Expand Up @@ -64,4 +64,12 @@ public function denormalize($data, $class, $format = null, array $context = arra
{
throw new LogicException(sprintf('Cannot denormalize with "%s".', \JsonSerializable::class));
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return __CLASS__ === \get_class($this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return __CLASS__ === \get_class($this);
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public function supportsDenormalization($data, $type, $format = null)
return parent::supportsDenormalization($data, $type, $format) && $this->supports($type);
}

/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod(): bool
{
return __CLASS__ === \get_class($this);
}

/**
* Checks if the given class has any non-static property.
*/
Expand Down
12 changes: 5 additions & 7 deletions 12 src/Symfony/Component/Serializer/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
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\Exception\LogicException;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;

/**
* Serializer serializes and deserializes data.
Expand Down Expand Up @@ -221,12 +221,11 @@ private function getNormalizer($data, ?string $format, array $context)
continue;
}

if (!$normalizer instanceof CacheableSupportsMethodInterface) {
if (!$normalizer instanceof CacheableSupportsMethodInterface || !$normalizer->hasCacheableSupportsMethod()) {
$this->normalizerCache[$format][$type][$k] = false;
} elseif ($normalizer->supportsNormalization($data, $format)) {
$this->normalizerCache[$format][$type][$k] = true;

return $normalizer;
break;
Copy link
Member Author

@nicolas-grekas nicolas-grekas May 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the bug spotted by @emodric: we cannot return here, as the non-cacheable normalizers weren't checked yet.

}
}
}
Expand Down Expand Up @@ -263,12 +262,11 @@ private function getDenormalizer($data, string $class, ?string $format, array $c
continue;
}

if (!$normalizer instanceof CacheableSupportsMethodInterface) {
if (!$normalizer instanceof CacheableSupportsMethodInterface || !$normalizer->hasCacheableSupportsMethod()) {
$this->denormalizerCache[$format][$class][$k] = false;
} elseif ($normalizer->supportsDenormalization(null, $class, $format)) {
$this->denormalizerCache[$format][$class][$k] = true;

return $normalizer;
break;
}
}
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.