Skip to content

Commit 07077a8

Browse files
authored
feat: add make commands to generate a custom data provider / persister (#1383)
1 parent 2997a41 commit 07077a8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

core/data-persisters.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ persist data for a given resource will be used.
2222

2323
## Creating a Custom Data Persister
2424

25+
If the [Symfony MakerBundle](https://symfony.com/doc/current/bundles/SymfonyMakerBundle) is installed in your project, you can use the following command to generate a custom data persister easily:
26+
```console
27+
bin/console make:data-persister
28+
```
29+
2530
To create a data persister, you have to implement the [`ContextAwareDataPersisterInterface`](https://github.com/api-platform/core/blob/main/src/DataPersister/ContextAwareDataPersisterInterface.php).
2631
This interface defines only 3 methods:
2732

core/data-providers.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ Note, that if your entity is not Doctrine-related, you need to flag the identifi
2727

2828
## Custom Collection Data Provider
2929

30+
If the [Symfony MakerBundle](https://symfony.com/doc/current/bundles/SymfonyMakerBundle) is installed in your project, you can use the following command to generate a custom collection data provider easily:
31+
```console
32+
bin/console make:data-provider --collection-only
33+
```
34+
3035
First, your `BlogPostCollectionDataProvider` has to implement the [`CollectionDataProviderInterface`](https://github.com/api-platform/core/blob/main/src/DataProvider/CollectionDataProviderInterface.php):
3136

3237
The `getCollection` method must return an `array`, a `Traversable` or a [`ApiPlatform\Core\DataProvider\PaginatorInterface`](https://github.com/api-platform/core/blob/main/src/DataProvider/PaginatorInterface.php) instance.
@@ -79,6 +84,11 @@ You can find a full working example in the [API Platform's demo application](htt
7984

8085
## Custom Item Data Provider
8186

87+
If the [Symfony MakerBundle](https://symfony.com/doc/current/bundles/SymfonyMakerBundle) is installed in your project, you can use the following command to generate a custom item data provider easily:
88+
```console
89+
bin/console make:data-provider --item-only
90+
```
91+
8292
The process is similar for item data providers. Create a `BlogPostItemDataProvider` implementing the [`ItemDataProviderInterface`](https://github.com/api-platform/core/blob/main/src/DataProvider/ItemDataProviderInterface.php)
8393
interface:
8494

0 commit comments

Comments
 (0)