From 7a175b9e08f6f8ad056e18b529776deec51b8f02 Mon Sep 17 00:00:00 2001 From: soyuka Date: Wed, 27 Oct 2021 16:46:13 +0200 Subject: [PATCH] serializer: default context configuration #16010 --- serializer.rst | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/serializer.rst b/serializer.rst index 92250d2f5a9..f61e2709dfe 100644 --- a/serializer.rst +++ b/serializer.rst @@ -175,6 +175,49 @@ You can pass the context like following:: DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s', ]); +You can also configure the default context through the framework +configuration: + +.. configuration-block:: + + .. code-block:: yaml + + # config/packages/framework.yaml + framework: + # ... + serializer: + default_context: + enable_max_depth: true + + .. code-block:: xml + + + + + + + + + + .. code-block:: php + + // config/packages/framework.php + use Symfony\Config\FrameworkConfig; + use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; + + return static function (FrameworkConfig $framework) { + $framework->serializer() + ->defaultContext([ + AbstractObjectNormalizer::ENABLE_MAX_DEPTH => true + ]) + ; + }; + +.. versionadded:: 5.4 + + The ability to configure the ``default_context`` option in the + Serializer was introduced in Symfony 5.4. + .. _serializer-using-serialization-groups-annotations: Using Serialization Groups Annotations