-
-
Notifications
You must be signed in to change notification settings - Fork 932
Description
This issue will lead to a documentation pull-request.
In 2.x, the data provider uses decorations. Actually, the default data provider will call it's decorated data providers and return the according method, or skip silently when a ResourceClassNotSupportedException
is thrown.
Based on the CollectionDataProvider
, my natural implementation (with symfony) would be to:
- declare a service
services:
my_custom.collection_data_provider:
class: 'Acme\DataProvider\BlogCollectionDataProvider'
decorates: 'api_platform.doctrine.orm.default.collection_data_provider'
arguments:
- '@doctrine'
- '@my_custom.collection_data_provider.inner'
- Have a class that throws a
ResourceClassNotSupportedException
if the current resource class is not supported:
//skipping the class/constructor declaration which implements the CollectionDataProviderInterface
public function getCollection(string $resourceClass, string $operationName)
{
if ($resourceClass !== 'Acme\Entity\BlogEntity') {
throw new ResourceClassNotSupportedException();
}
//fetch data
}
What I don't understand, is that if my custom data provider decorates the api_platform.doctrine.orm.default.collection_data_provider
, I get something like:
return $this->services['my_custom.collection_data_provider'] = new \Acme\DataProvider\BlogCollectionDataProvider(
$a,
new \ApiPlatform\Core\Bridge\Doctrine\Orm\CollectionDataProvider($a, ...)
);
The default collection data provider will therefore never get any decorations, and my custom data provider will always throw an un-catched ResourceClassNotSupportedException
.
Is this a matter of decoration priorities or am I doing something wrong?
Thanks!