Skip to content

Commit e30d1e6

Browse files
authored
Merge pull request #1422 from PierreThibaudeau/update_2.7
docs: 2.7 update
2 parents 802f3da + 5a6449e commit e30d1e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+910
-1177
lines changed

admin/handling-relations.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,9 @@ This API uses the following PHP code:
150150
```php
151151
<?php
152152
// api/src/Entity/Review.php
153-
154153
namespace App\Entity;
155154

156-
use ApiPlatform\Core\Annotation\ApiResource;
155+
use ApiPlatform\Metadata\ApiResource;
157156
use Doctrine\ORM\Mapping as ORM;
158157

159158
/**
@@ -179,11 +178,10 @@ class Review
179178
```php
180179
<?php
181180
// api/src/Entity/Book.php
182-
183181
namespace App\Entity;
184182

185183
use ApiPlatform\Core\Annotation\ApiFilter;
186-
use ApiPlatform\Core\Annotation\ApiResource;
184+
use ApiPlatform\Metadata\ApiResource;
187185
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
188186
use Doctrine\Common\Collections\ArrayCollection;
189187
use Doctrine\ORM\Mapping as ORM;

admin/performance.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ you can make sure the authors are retrieved in one go by writing:
1717
```php
1818
<?php
1919
// api/src/Entity/Author.php
20-
2120
namespace App\Entity;
2221

2322
use ApiPlatform\Core\Annotation\ApiFilter;
24-
use ApiPlatform\Core\Annotation\ApiResource;
2523
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
24+
use ApiPlatform\Metadata\ApiResource;
2625
use Doctrine\ORM\Mapping as ORM;
2726

2827
/**
@@ -35,8 +34,8 @@ class Author
3534
* @ORM\Column(type="integer")
3635
* @ORM\GeneratedValue
3736
* @ORM\Id
38-
* @ApiFilter(SearchFilter::class, strategy="exact")
3937
*/
38+
#[ApiFilter(SearchFilter::class, strategy: "exact")]
4039
public $id;
4140

4241
/**

admin/schema.org.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ To configure which property should be shown to represent your entity, map the pr
1616

1717
```php
1818
// api/src/Entity/Person.php
19+
...
1920

20-
/**
21-
* @ApiProperty(iri="http://schema.org/name")
22-
*/
21+
#[ApiProperty(types: ["http://schema.org/name"])]
2322
private $name;
23+
24+
...
2425
```
2526

2627
## Emails, URLs and Identifiers

admin/validation.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ For instance, with API Platform Core as backend, if you write the following:
1212
```php
1313
<?php
1414
// api/src/Entity/Book.php
15+
namespace App\Entity;
1516

16-
use ApiPlatform\Core\Annotation\ApiResource;
17+
use ApiPlatform\Metadata\ApiResource;
1718
use Symfony\Component\Validator\Constraints as Assert;
1819

19-
/**
20-
* @ApiResource
21-
*/
20+
#[ApiResource]
2221
class Book
2322
{
2423
/**
@@ -47,13 +46,12 @@ For example if you have this code:
4746
```php
4847
<?php
4948
// api/src/Entity/Book.php
49+
namespace App\Entity;
5050

51-
use ApiPlatform\Core\Annotation\ApiResource;
51+
use ApiPlatform\Metadata\ApiResource;
5252
use Symfony\Component\Validator\Constraints as Assert;
5353

54-
/**
55-
* @ApiResource
56-
*/
54+
#[ApiResource]
5755
class Book
5856
{
5957
/**

core/content-negotiation.md

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,11 @@ The `format` attribute can be used as a shortcut, it sets both the `input_format
102102
```php
103103
<?php
104104
// api/src/Entity/Book.php
105-
106105
namespace App\Entity;
107106
108-
use ApiPlatform\Core\Annotation\ApiResource;
107+
use ApiPlatform\Metadata\ApiResource;
109108
110-
#[ApiResource(formats: ['xml', 'jsonld', 'csv' => ['text/csv']])]
109+
#[ApiResource(formats: ['xml', 'jsonld', 'csv' => ['text/csv']])]
111110
class Book
112111
{
113112
// ...
@@ -127,21 +126,17 @@ You can specify different accepted formats at operation level too, it's especial
127126
```php
128127
<?php
129128
// api/src/Entity/Book.php
130-
131129
namespace App\Entity;
132130
133-
use ApiPlatform\Core\Annotation\ApiResource;
134-
135-
#[ApiResource(
136-
formats: ['jsonld', 'csv' => ['text/csv']],
137-
itemOperations: [
138-
'patch' => [
139-
'input_formats' => [
140-
'json' => ['application/merge-patch+json'],
141-
],
142-
],
143-
],
144-
)]
131+
use ApiPlatform\Metadata\ApiResource;
132+
use ApiPlatform\Metadata\Patch;
133+
use ApiPlatform\Metadata\GetCollection;
134+
use ApiPlatform\Metadata\Post;
135+
136+
#[ApiResource(formats: ['jsonld', 'csv' => ['text/csv']])]
137+
#[Patch(inputFormats: ['json' => ['application/merge-patch+json']])]
138+
#[GetCollection]
139+
#[Post]
145140
class Book
146141
{
147142
// ...
@@ -227,7 +222,6 @@ services:
227222
```php
228223
<?php
229224
// api/src/Serializer/CustomItemNormalizer.php
230-
231225
namespace App\Serializer;
232226
233227
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
@@ -274,7 +268,6 @@ flatten or remove overly complex relations:
274268
```php
275269
<?php
276270
// api/src/Serializer/CustomItemNormalizer.php
277-
278271
namespace App\Serializer;
279272
280273
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

core/controllers.md

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ First, let's create your custom operation:
3131
```php
3232
<?php
3333
// api/src/Controller/CreateBookPublication.php
34-
3534
namespace App\Controller;
3635

3736
use App\Entity\Book;
@@ -90,18 +89,20 @@ The routing has not been configured yet because we will add it at the resource c
9089
```php
9190
<?php
9291
// api/src/Entity/Book.php
92+
namespace App\Entity;
9393

94-
use ApiPlatform\Core\Annotation\ApiResource;
94+
use ApiPlatform\Metadata\ApiResource;
95+
use ApiPlatform\Metadata\Get;
96+
use ApiPlatform\Metadata\Post;
9597
use App\Controller\CreateBookPublication;
9698

97-
#[ApiResource(itemOperations: [
98-
'get',
99-
'post_publication' => [
100-
'method' => 'POST',
101-
'path' => '/books/{id}/publication',
102-
'controller' => CreateBookPublication::class,
103-
],
104-
])]
99+
#[ApiResource]
100+
#[Get]
101+
#[Post(
102+
name: 'publication',
103+
uriTemplate: '/books/{id}/publication',
104+
controller: CreateBookPublication::class
105+
)]
105106
class Book
106107
{
107108
// ...
@@ -155,20 +156,22 @@ You may want different serialization groups for your custom operations. Just con
155156
```php
156157
<?php
157158
// api/src/Entity/Book.php
159+
namespace App\Entity;
158160

159-
use ApiPlatform\Core\Annotation\ApiResource;
161+
use ApiPlatform\Metadata\ApiResource;
162+
use ApiPlatform\Metadata\Get;
163+
use ApiPlatform\Metadata\Post;
160164
use App\Controller\CreateBookPublication;
161165
use Symfony\Component\Serializer\Annotation\Groups;
162166

163-
#[ApiResource(itemOperations: [
164-
'get',
165-
'post_publication' => [
166-
'method' => 'POST',
167-
'path' => '/books/{id}/publication',
168-
'controller' => CreateBookPublication::class,
169-
'normalization_context' => ['groups' => 'publication'],
170-
],
171-
])]
167+
#[ApiResource]
168+
#[Get]
169+
#[Post(
170+
name: 'publication',
171+
uriTemplate: '/books/{id}/publication',
172+
controller: CreateBookPublication::class,
173+
normalizationContext: ['groups' => 'publication']
174+
)]
172175
class Book
173176
{
174177
// ...
@@ -231,19 +234,21 @@ operation attribute:
231234
```php
232235
<?php
233236
// api/src/Entity/Book.php
237+
namespace App\Entity;
234238

235-
use ApiPlatform\Core\Annotation\ApiResource;
239+
use ApiPlatform\Metadata\ApiResource;
240+
use ApiPlatform\Metadata\Get;
241+
use ApiPlatform\Metadata\Post;
236242
use App\Controller\CreateBookPublication;
237243

238-
#[ApiResource(itemOperations: [
239-
'get',
240-
'post_publication' => [
241-
'method' => 'POST',
242-
'path' => '/books/{id}/publication',
243-
'controller' => CreateBookPublication::class,
244-
'read' => false,
245-
],
246-
])]
244+
#[ApiResource]
245+
#[Get]
246+
#[Post(
247+
name: 'publication',
248+
uriTemplate: '/books/{id}/publication',
249+
controller: CreateBookPublication::class,
250+
read: false
251+
)]
247252
class Book
248253
{
249254
// ...
@@ -309,14 +314,16 @@ First, let's create your resource configuration:
309314
```php
310315
<?php
311316
// api/src/Entity/Book.php
317+
namespace App\Entity;
312318

313-
use ApiPlatform\Core\Annotation\ApiResource;
319+
use ApiPlatform\Metadata\ApiResource;
320+
use ApiPlatform\Metadata\Get;
321+
use ApiPlatform\Metadata\Post;
314322

315-
#[ApiResource(itemOperations: [
316-
'get',
317-
'post_publication' => ['route_name' => 'book_post_publication'],
318-
'book_post_discontinuation',
319-
])]
323+
#[ApiResource]
324+
#[Get]
325+
#[Post(name: 'publication', routeName: 'book_post_publication')]
326+
#[Post(name: 'book_post_discontinuation')]
320327
class Book
321328
{
322329
// ...
@@ -361,7 +368,6 @@ and its related route using annotations:
361368
```php
362369
<?php
363370
// api/src/Controller/CreateBookPublication.php
364-
365371
namespace App\Controller;
366372

367373
use App\Entity\Book;
@@ -406,7 +412,6 @@ the same thing as the previous example:
406412
```php
407413
<?php
408414
// api/src/Controller/BookController.php
409-
410415
namespace App\Controller;
411416

412417
use App\Entity\Book;

core/data-persisters.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ persist data for a given resource will be used.
2323
## Creating a Custom Data Persister
2424

2525
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+
2627
```console
2728
bin/console make:data-persister
2829
```
@@ -190,6 +191,7 @@ final class BlogPostDataPersister implements ContextAwareDataPersisterInterface,
190191
```
191192

192193
This is very useful when using [`Messenger` with API Platform](messenger.md) as you may want to do something asynchronously with the data but still call the default Doctrine data persister, for example:
194+
193195
```php
194196
namespace App\DataPersister;
195197

@@ -230,6 +232,7 @@ final class BlogPostDataPersister implements ContextAwareDataPersisterInterface,
230232
}
231233
}
232234
```
235+
233236
```yaml
234237
# api/config/services.yaml
235238
services:

core/data-providers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ Both implementations can also implement a third, optional, interface called
2323
if you want to limit their effects to a single resource or operation.
2424

2525
In the following examples we will create custom data providers for an entity class called `App\Entity\BlogPost`.
26-
Note, that if your entity is not Doctrine-related, you need to flag the identifier property by using `@ApiProperty(identifier=true)` for things to work properly (see also [Entity Identifier Case](serialization.md#entity-identifier-case)).
26+
Note, that if your entity is not Doctrine-related, you need to flag the identifier property by using `#[ApiProperty(identifier: true)]` for things to work properly (see also [Entity Identifier Case](serialization.md#entity-identifier-case)).
2727

2828
## Custom Collection Data Provider
2929

3030
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+
3132
```console
3233
bin/console make:data-provider --collection-only
3334
```
@@ -85,6 +86,7 @@ You can find a full working example in the [API Platform's demo application](htt
8586
## Custom Item Data Provider
8687

8788
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:
89+
8890
```console
8991
bin/console make:data-provider --item-only
9092
```
@@ -266,8 +268,6 @@ using it within your data provider.
266268
<?php
267269
// api/src/DataProvider/CustomCollectionDataProvider.php
268270
269-
declare(strict_types=1);
270-
271271
namespace App\DataProvider;
272272
273273
use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;

0 commit comments

Comments
 (0)