Skip to content

Commit d3b690e

Browse files
author
abluchet
committed
Add service aliases for autowiring in symfony>3.4
1 parent bd9aea7 commit d3b690e

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@
119119
<tag name="api_platform.doctrine.orm.query_extension.item" priority="64" />
120120
<tag name="api_platform.doctrine.orm.query_extension.collection" priority="64" />
121121
</service>
122+
<service id="ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\EagerLoadingExtension" alias="api_platform.doctrine.orm.query_extension.eager_loading" />
122123

123124
<service id="api_platform.doctrine.orm.query_extension.filter" class="ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\FilterExtension" public="false">
124125
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
125126
<argument type="service" id="api_platform.filter_locator" />
126127

127128
<tag name="api_platform.doctrine.orm.query_extension.collection" priority="32" />
128129
</service>
130+
<service id="ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\FilterExtension" alias="api_platform.doctrine.orm.query_extension.filter" />
129131

130132
<!-- This needs to be executed right after the filter extension -->
131133

@@ -135,6 +137,7 @@
135137

136138
<tag name="api_platform.doctrine.orm.query_extension.collection" priority="31" />
137139
</service>
140+
<service id="ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\FilterEagerLoadingExtension" alias="api_platform.doctrine.orm.query_extension.filter_eager_loading" />
138141

139142
<service id="api_platform.doctrine.orm.query_extension.pagination" class="ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\PaginationExtension" public="false">
140143
<argument type="service" id="doctrine" />
@@ -151,13 +154,15 @@
151154

152155
<tag name="api_platform.doctrine.orm.query_extension.collection" priority="8" />
153156
</service>
157+
<service id="ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\PaginationExtension" alias="api_platform.doctrine.orm.query_extension.pagination" />
154158

155159
<service id="api_platform.doctrine.orm.query_extension.order" class="ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\OrderExtension" public="false">
156160
<argument>%api_platform.collection.order%</argument>
157161
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
158162

159163
<tag name="api_platform.doctrine.orm.query_extension.collection" priority="16" />
160164
</service>
165+
<service id="ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\OrderExtension" alias="api_platform.doctrine.orm.query_extension.order" />
161166
</services>
162167

163168
</container>

src/Bridge/Symfony/Bundle/Resources/config/metadata/metadata.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<argument type="service" id="api_platform.cache.metadata.resource" />
1212
<argument type="service" id="api_platform.metadata.resource.name_collection_factory.cached.inner" />
1313
</service>
14+
<service id="ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface" alias="api_platform.metadata.resource.name_collection_factory" />
1415

1516
<!-- Resource metadata -->
1617

@@ -27,9 +28,12 @@
2728
<argument type="service" id="api_platform.metadata.resource.metadata_factory.cached.inner" />
2829
</service>
2930

31+
<service id="ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface" alias="api_platform.metadata.resource.metadata_factory" />
32+
3033
<!-- Property name collection -->
3134

3235
<service id="api_platform.metadata.property.name_collection_factory" alias="api_platform.metadata.property.name_collection_factory.property_info" />
36+
<service id="ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface" alias="api_platform.metadata.property.name_collection_factory" />
3337

3438
<service id="api_platform.metadata.property.name_collection_factory.property_info" class="ApiPlatform\Core\Bridge\Symfony\PropertyInfo\Metadata\Property\PropertyInfoPropertyNameCollectionFactory" public="false">
3539
<argument type="service" id="api_platform.property_info" />
@@ -69,6 +73,8 @@
6973
<argument type="service" id="api_platform.metadata.property.metadata_factory.cached.inner" />
7074
</service>
7175

76+
<service id="ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface" alias="api_platform.metadata.property.metadata_factory" />
77+
7278
<!-- Cache -->
7379

7480
<service id="api_platform.cache.metadata.resource" parent="cache.system" public="false">

tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,22 @@
1515

1616
use ApiPlatform\Core\Api\FilterInterface;
1717
use ApiPlatform\Core\Api\IriConverterInterface;
18+
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\EagerLoadingExtension;
19+
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\FilterEagerLoadingExtension;
20+
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\FilterExtension;
21+
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\OrderExtension;
22+
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\PaginationExtension;
1823
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
1924
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryItemExtensionInterface;
2025
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\ApiPlatformExtension;
2126
use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;
2227
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
2328
use ApiPlatform\Core\DataProvider\SubresourceDataProviderInterface;
2429
use ApiPlatform\Core\Exception\InvalidArgumentException;
30+
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
31+
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
32+
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
33+
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
2534
use ApiPlatform\Core\Serializer\SerializerContextBuilderInterface;
2635
use ApiPlatform\Core\Tests\Fixtures\TestBundle\TestBundle;
2736
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
@@ -246,7 +255,7 @@ public function testResourcesToWatchWithUnsupportedMappingType()
246255
{
247256
$this->extension->load(
248257
array_merge_recursive(self::DEFAULT_CONFIG, ['api_platform' => ['mapping' => ['paths' => [__FILE__]]]]),
249-
$this->getPartialContainerBuilderProphecy()->reveal()
258+
$this->getPartialContainerBuilderProphecy(false)->reveal()
250259
);
251260
}
252261

@@ -283,7 +292,7 @@ public function testNotRegisterHttpCacheWhenEnabledWithNoVarnishServer()
283292
$this->extension->load($config, $containerBuilder);
284293
}
285294

286-
private function getPartialContainerBuilderProphecy()
295+
private function getPartialContainerBuilderProphecy($test = false)
287296
{
288297
$containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);
289298
$childDefinitionProphecy = $this->prophesize(ChildDefinition::class);
@@ -460,6 +469,10 @@ private function getPartialContainerBuilderProphecy()
460469
CollectionDataProviderInterface::class => 'api_platform.collection_data_provider',
461470
ItemDataProviderInterface::class => 'api_platform.item_data_provider',
462471
SubresourceDataProviderInterface::class => 'api_platform.subresource_data_provider',
472+
ResourceNameCollectionFactoryInterface::class => 'api_platform.metadata.resource.name_collection_factory',
473+
ResourceMetadataFactoryInterface::class => 'api_platform.metadata.resource.metadata_factory',
474+
PropertyNameCollectionFactoryInterface::class => 'api_platform.metadata.property.name_collection_factory',
475+
PropertyMetadataFactoryInterface::class => 'api_platform.metadata.property.metadata_factory',
463476
];
464477

465478
foreach ($aliases as $alias => $service) {
@@ -581,7 +594,18 @@ private function getBaseContainerBuilderProphecy()
581594
$containerBuilderProphecy->setDefinition($definition, Argument::type(Definition::class))->shouldBeCalled();
582595
}
583596

584-
$containerBuilderProphecy->setAlias('api_platform.http_cache.purger', 'api_platform.http_cache.purger.varnish')->shouldBeCalled();
597+
$aliases = [
598+
'api_platform.http_cache.purger' => 'api_platform.http_cache.purger.varnish',
599+
EagerLoadingExtension::class => 'api_platform.doctrine.orm.query_extension.eager_loading',
600+
FilterExtension::class => 'api_platform.doctrine.orm.query_extension.filter',
601+
FilterEagerLoadingExtension::class => 'api_platform.doctrine.orm.query_extension.filter_eager_loading',
602+
PaginationExtension::class => 'api_platform.doctrine.orm.query_extension.pagination',
603+
OrderExtension::class => 'api_platform.doctrine.orm.query_extension.order',
604+
];
605+
606+
foreach ($aliases as $alias => $service) {
607+
$containerBuilderProphecy->setAlias($alias, $service)->shouldBeCalled();
608+
}
585609

586610
return $containerBuilderProphecy;
587611
}

0 commit comments

Comments
 (0)