Skip to content

Commit e3dae2b

Browse files
authored
Data Provider Exception vs Restricted interface (#1197)
* Data Provider seems misused Conflict between ApiPlatform\Core\Exception\ResourceClassNotSupportedException and ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface usages * Update data-providers.md
1 parent 9910fb9 commit e3dae2b

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

core/data-providers.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ namespace App\DataProvider;
4040

4141
use ApiPlatform\Core\DataProvider\ContextAwareCollectionDataProviderInterface;
4242
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
43-
use ApiPlatform\Core\Exception\ResourceClassNotSupportedException;
4443
use App\Entity\BlogPost;
4544

4645
final class BlogPostCollectionDataProvider implements ContextAwareCollectionDataProviderInterface, RestrictedDataProviderInterface
@@ -74,8 +73,7 @@ services:
7473
7574
Tagging the service with the tag `api_platform.collection_data_provider` will enable API Platform Core to automatically
7675
register and use this data provider. The optional attribute `priority` allows you to define the order in which the
77-
data providers are called. The first data provider not throwing a `ApiPlatform\Core\Exception\ResourceClassNotSupportedException`
78-
will be used.
76+
data providers are called. Implementing the `ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface` let you restrict the data provider use. Alternatively, you can also throw a `ApiPlatform\Core\Exception\ResourceClassNotSupportedException`. Without the `RestrictedDataProviderInterface`, the first data provider not throwing this exception will be used.
7977

8078
You can find a full working example in the [API Platform's demo application](https://github.com/api-platform/demo/blob/master/api/src/DataProvider/TopBookCollectionDataProvider.php).
8179

@@ -94,7 +92,6 @@ namespace App\DataProvider;
9492
9593
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
9694
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
97-
use ApiPlatform\Core\Exception\ResourceClassNotSupportedException;
9895
use App\Entity\BlogPost;
9996
10097
final class BlogPostItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface
@@ -145,7 +142,6 @@ namespace App\DataProvider;
145142
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
146143
use ApiPlatform\Core\DataProvider\SerializerAwareDataProviderInterface;
147144
use ApiPlatform\Core\DataProvider\SerializerAwareDataProviderTrait;
148-
use ApiPlatform\Core\Exception\ResourceClassNotSupportedException;
149145
use App\Entity\BlogPost;
150146
151147
final class BlogPostItemDataProvider implements ItemDataProviderInterface, SerializerAwareDataProviderInterface
@@ -203,7 +199,6 @@ use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryResultItemExtensionInter
203199
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator;
204200
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
205201
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
206-
use ApiPlatform\Core\Exception\ResourceClassNotSupportedException;
207202
use App\Entity\BlogPost;
208203
use Doctrine\Persistence\ManagerRegistry;
209204

0 commit comments

Comments
 (0)