Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 59a419b

Browse files
committed
use the NormalizerAwareInterface to prevent circular references
1 parent 430f4ef commit 59a419b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

serializer/custom_normalizer.rst

+7-5
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@ to customize the normalized data. To do that, leverage the ``ObjectNormalizer``:
2323
use App\Entity\Topic;
2424
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2525
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
26-
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
26+
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
27+
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
28+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2729

28-
class TopicNormalizer implements ContextAwareNormalizerInterface
30+
class TopicNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
2931
{
32+
use NormalizerAwareTrait;
33+
3034
private $router;
31-
private $normalizer;
3235

33-
public function __construct(UrlGeneratorInterface $router, ObjectNormalizer $normalizer)
36+
public function __construct(UrlGeneratorInterface $router)
3437
{
3538
$this->router = $router;
36-
$this->normalizer = $normalizer;
3739
}
3840

3941
public function normalize($topic, $format = null, array $context = [])

0 commit comments

Comments
 (0)