Skip to content

Add service aliases for autowiring in symfony>3.4 #1557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Bridge/Symfony/Bundle/Resources/config/doctrine_orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,15 @@
<tag name="api_platform.doctrine.orm.query_extension.item" priority="64" />
<tag name="api_platform.doctrine.orm.query_extension.collection" priority="64" />
</service>
<service id="ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\EagerLoadingExtension" alias="api_platform.doctrine.orm.query_extension.eager_loading" />

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

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

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

Expand All @@ -135,6 +137,7 @@

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

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

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

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

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

</container>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<argument type="service" id="api_platform.cache.metadata.resource" />
<argument type="service" id="api_platform.metadata.resource.name_collection_factory.cached.inner" />
</service>
<service id="ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface" alias="api_platform.metadata.resource.name_collection_factory" />

<!-- Resource metadata -->

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

<service id="ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface" alias="api_platform.metadata.resource.metadata_factory" />

<!-- Property name collection -->

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

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

<service id="ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface" alias="api_platform.metadata.property.metadata_factory" />

<!-- Cache -->

<service id="api_platform.cache.metadata.resource" parent="cache.system" public="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@

use ApiPlatform\Core\Api\FilterInterface;
use ApiPlatform\Core\Api\IriConverterInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\EagerLoadingExtension;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\FilterEagerLoadingExtension;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\FilterExtension;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\OrderExtension;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\PaginationExtension;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryItemExtensionInterface;
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\ApiPlatformExtension;
use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
use ApiPlatform\Core\DataProvider\SubresourceDataProviderInterface;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
use ApiPlatform\Core\Serializer\SerializerContextBuilderInterface;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\TestBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
Expand Down Expand Up @@ -246,7 +255,7 @@ public function testResourcesToWatchWithUnsupportedMappingType()
{
$this->extension->load(
array_merge_recursive(self::DEFAULT_CONFIG, ['api_platform' => ['mapping' => ['paths' => [__FILE__]]]]),
$this->getPartialContainerBuilderProphecy()->reveal()
$this->getPartialContainerBuilderProphecy(false)->reveal()
);
}

Expand Down Expand Up @@ -283,7 +292,7 @@ public function testNotRegisterHttpCacheWhenEnabledWithNoVarnishServer()
$this->extension->load($config, $containerBuilder);
}

private function getPartialContainerBuilderProphecy()
private function getPartialContainerBuilderProphecy($test = false)
{
$containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);
$childDefinitionProphecy = $this->prophesize(ChildDefinition::class);
Expand Down Expand Up @@ -460,6 +469,10 @@ private function getPartialContainerBuilderProphecy()
CollectionDataProviderInterface::class => 'api_platform.collection_data_provider',
ItemDataProviderInterface::class => 'api_platform.item_data_provider',
SubresourceDataProviderInterface::class => 'api_platform.subresource_data_provider',
ResourceNameCollectionFactoryInterface::class => 'api_platform.metadata.resource.name_collection_factory',
ResourceMetadataFactoryInterface::class => 'api_platform.metadata.resource.metadata_factory',
PropertyNameCollectionFactoryInterface::class => 'api_platform.metadata.property.name_collection_factory',
PropertyMetadataFactoryInterface::class => 'api_platform.metadata.property.metadata_factory',
];

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

$containerBuilderProphecy->setAlias('api_platform.http_cache.purger', 'api_platform.http_cache.purger.varnish')->shouldBeCalled();
$aliases = [
'api_platform.http_cache.purger' => 'api_platform.http_cache.purger.varnish',
EagerLoadingExtension::class => 'api_platform.doctrine.orm.query_extension.eager_loading',
FilterExtension::class => 'api_platform.doctrine.orm.query_extension.filter',
FilterEagerLoadingExtension::class => 'api_platform.doctrine.orm.query_extension.filter_eager_loading',
PaginationExtension::class => 'api_platform.doctrine.orm.query_extension.pagination',
OrderExtension::class => 'api_platform.doctrine.orm.query_extension.order',
];

foreach ($aliases as $alias => $service) {
$containerBuilderProphecy->setAlias($alias, $service)->shouldBeCalled();
}

return $containerBuilderProphecy;
}
Expand Down