From 74144506982e9a6bb7755927602f8e74e40ee708 Mon Sep 17 00:00:00 2001 From: Julien Deniau Date: Tue, 5 Dec 2017 10:13:56 +0100 Subject: [PATCH] Update data-provider to remove deprecation `ChainItemDataProvider` and `ChainCollectionDataProvider` now deprecates throwing a `ResourceClassNotSupportedException` in favor of implementing `RestrictedDataProviderInterface`, so I updated the documentation to match this recommandation. --- core/data-providers.md | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/core/data-providers.md b/core/data-providers.md index ff856ea5721..b4e93f1fc9f 100644 --- a/core/data-providers.md +++ b/core/data-providers.md @@ -35,19 +35,20 @@ namespace AppBundle\DataProvider; use AppBundle\Entity\BlogPost; use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface; -use ApiPlatform\Core\Exception\ResourceClassNotSupportedException; +use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; -final class BlogPostCollectionDataProvider implements CollectionDataProviderInterface +final class BlogPostCollectionDataProvider implements CollectionDataProviderInterface, RestrictedDataProviderInterface { public function getCollection(string $resourceClass, string $operationName = null) { - if (BlogPost::class !== $resourceClass) { - throw new ResourceClassNotSupportedException(); - } - // Retrieve the blog post collection from somewhere return [new BlogPost(1), new BlogPost(2)]; } + + public function supports(string $resourceClass, string $operationName = null): bool + { + return BlogPost::class === $resourceClass; + } } ``` @@ -84,18 +85,20 @@ namespace AppBundle\DataProvider; use AppBundle\Entity\BlogPost; use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\Exception\ResourceClassNotSupportedException; +use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; -final class BlogPostItemDataProvider implements ItemDataProviderInterface +final class BlogPostItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface { - public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []) { - if (BlogPost::class !== $resourceClass) { - throw new ResourceClassNotSupportedException(); - } - + public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []) + { // Retrieve the blog post item from somewhere then return it or null if not found return new BlogPost($id); } + + public function supports(string $resourceClass, string $operationName = null): bool + { + return BlogPost::class === $resourceClass; + } } ```