Procházet zdrojové kódy

[Serializer] Add checks for SerializerAwareInterface

Jordi Boggiano před 14 roky
rodič
revize
3ecc9602e4
1 změnil soubory, kde provedl 6 přidání a 2 odebrání
  1. 6 2
      src/Symfony/Component/Serializer/Serializer.php

+ 6 - 2
src/Symfony/Component/Serializer/Serializer.php

@@ -162,7 +162,9 @@ class Serializer implements SerializerInterface
     public function addNormalizer(NormalizerInterface $normalizer)
     {
         $this->normalizers[] = $normalizer;
-        $normalizer->setSerializer($this);
+        if ($normalizer instanceof SerializerAwareInterface) {
+            $normalizer->setSerializer($this);
+        }
     }
 
     /**
@@ -187,7 +189,9 @@ class Serializer implements SerializerInterface
     public function setEncoder($format, EncoderInterface $encoder)
     {
         $this->encoders[$format] = $encoder;
-        $encoder->setSerializer($this);
+        if ($encoder instanceof SerializerAwareInterface) {
+            $encoder->setSerializer($this);
+        }
     }
 
     /**