Skip to content

Commit

Permalink
feature #22011 [FrameworkBundle][Serializer] Add option to register a…
Browse files Browse the repository at this point in the history
… circular_reference_handler (lyrixx)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[FrameworkBundle][Serializer] Add option to register a circular_reference_handler

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

---

Right now, it's quite hard (especially for new comers) to register a CircularReferenceHandler:

![screenshot1](https://cloud.githubusercontent.com/assets/408368/23959193/ce19bcec-09a4-11e7-82c7-80abd7b7f602.png)

---

This PR introduce an option to wire a service to the internal Object Normalizer.

Commits
-------

0a638f5 [FrameworkBundle][Serializer] Add option to register a "circular_reference_handler"
  • Loading branch information
fabpot committed Mar 22, 2017
2 parents 7b60064 + 0a638f5 commit 065bf48
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Expand Up @@ -686,6 +686,7 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode)
->booleanNode('enable_annotations')->{!class_exists(FullStack::class) && class_exists(Annotation::class) ? 'defaultTrue' : 'defaultFalse'}()->end()
->scalarNode('cache')->end()
->scalarNode('name_converter')->end()
->scalarNode('circular_reference_handler')->end()
->end()
->end()
->end()
Expand Down
Expand Up @@ -1294,6 +1294,10 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
if (isset($config['name_converter']) && $config['name_converter']) {
$container->getDefinition('serializer.normalizer.object')->replaceArgument(1, new Reference($config['name_converter']));
}

if (isset($config['circular_reference_handler']) && $config['circular_reference_handler']) {
$container->getDefinition('serializer.normalizer.object')->addMethodCall('setCircularReferenceHandler', array(new Reference($config['circular_reference_handler'])));
}
}

/**
Expand Down

0 comments on commit 065bf48

Please sign in to comment.