Skip to content

Commit

Permalink
feature #16947 [FrameworkBundle] PropertyInfo: register the Serialize…
Browse files Browse the repository at this point in the history
…rExtractor (dunglas)

This PR was squashed before being merged into the 3.1-dev branch (closes #16947).

Discussion
----------

[FrameworkBundle] PropertyInfo: register the SerializerExtractor

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

Commits
-------

4422103 [FrameworkBundle] PropertyInfo: register the SerializerExtractor
  • Loading branch information
dunglas committed Feb 2, 2016
2 parents 83b53f4 + 4422103 commit 0bacaba
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
Expand Up @@ -31,17 +31,19 @@ public function process(ContainerBuilder $container)
return;
}

$definition = $container->getDefinition('property_info');

$listExtractors = $this->findAndSortTaggedServices('property_info.list_extractor', $container);
$container->getDefinition('property_info')->replaceArgument(0, $listExtractors);
$definition->replaceArgument(0, $listExtractors);

$typeExtractors = $this->findAndSortTaggedServices('property_info.type_extractor', $container);
$container->getDefinition('property_info')->replaceArgument(1, $typeExtractors);
$definition->replaceArgument(1, $typeExtractors);

$descriptionExtractors = $this->findAndSortTaggedServices('property_info.description_extractor', $container);
$container->getDefinition('property_info')->replaceArgument(2, $descriptionExtractors);
$definition->replaceArgument(2, $descriptionExtractors);

$accessExtractors = $this->findAndSortTaggedServices('property_info.access_extractor', $container);
$container->getDefinition('property_info')->replaceArgument(3, $accessExtractors);
$definition->replaceArgument(3, $accessExtractors);
}

/**
Expand Down
Expand Up @@ -55,5 +55,12 @@

<!-- Name converter -->
<service id="serializer.name_converter.camel_case_to_snake_case" class="Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter" public="false" />

<!-- PropertyInfo extractor -->
<service id="property_info.serializer_extractor" class="Symfony\Component\PropertyInfo\Extractor\SerializerExtractor" public="false">
<argument type="service" id="serializer.mapping.class_metadata_factory" />

<tag name="property_info.list_extractor" priority="-999" />
</service>
</services>
</container>
Expand Up @@ -32,7 +32,8 @@ public function testServicesAreOrderedAccordingToPriority()

$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array('findTaggedServiceIds'));

$container->expects($this->any())
$container
->expects($this->any())
->method('findTaggedServiceIds')
->will($this->returnValue($services));

Expand All @@ -53,9 +54,11 @@ public function testReturningEmptyArrayWhenNoService()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array('findTaggedServiceIds'));

$container->expects($this->any())
$container
->expects($this->any())
->method('findTaggedServiceIds')
->will($this->returnValue(array()));
->will($this->returnValue(array()))
;

$propertyInfoPass = new PropertyInfoPass();

Expand Down
Expand Up @@ -441,6 +441,18 @@ public function testSerializerEnabled()
$this->assertEquals(new Reference('serializer.name_converter.camel_case_to_snake_case'), $container->getDefinition('serializer.normalizer.object')->getArgument(1));
}

public function testRegisterSerializerExtractor()
{
$container = $this->createContainerFromFile('full');

$serializerExtractorDefinition = $container->getDefinition('property_info.serializer_extractor');

$this->assertEquals('serializer.mapping.class_metadata_factory', $serializerExtractorDefinition->getArgument(0)->__toString());
$this->assertFalse($serializerExtractorDefinition->isPublic());
$tag = $serializerExtractorDefinition->getTag('property_info.list_extractor');
$this->assertEquals(array('priority' => -999), $tag[0]);
}

public function testAssetHelperWhenAssetsAreEnabled()
{
$container = $this->createContainerFromFile('full');
Expand Down

0 comments on commit 0bacaba

Please sign in to comment.