Skip to content

Commit 1e2fdab

Browse files
soyukaalanpoulain
andauthored
fix: 2.7 and 3.0 metadata system (#1519)
* doc: new metadata * State processors/providers * bump * fix links * lint * lint * Apply suggestions from code review Co-authored-by: Alan Poulain <[email protected]> * review Co-authored-by: Alan Poulain <[email protected]>
1 parent bcb31f0 commit 1e2fdab

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

+1029
-1164
lines changed

admin/handling-relations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ class Review
170170
// api/src/Entity/Book.php
171171
namespace App\Entity;
172172

173-
use ApiPlatform\Core\Annotation\ApiFilter;
173+
use ApiPlatform\Metadata\ApiFilter;
174174
use ApiPlatform\Metadata\ApiResource;
175-
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
175+
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
176176
use Doctrine\Common\Collections\ArrayCollection;
177177
use Doctrine\Common\Collections\Collection;
178178
use Doctrine\ORM\Mapping as ORM;

admin/performance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ you can make sure the authors are retrieved in one go by writing:
1919
// api/src/Entity/Author.php
2020
namespace App\Entity;
2121

22-
use ApiPlatform\Core\Annotation\ApiFilter;
23-
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
22+
use ApiPlatform\Metadata\ApiFilter;
23+
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
2424
use ApiPlatform\Metadata\ApiResource;
2525
use Doctrine\ORM\Mapping as ORM;
2626

admin/validation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ API Platform Admin manages automatically two types of validation: client-side va
77
If the API documentation indicates that a field is mandatory,
88
API Platform Admin will automatically add a [required client-side validation](https://marmelab.com/react-admin/CreateEdit.html#per-input-validation-built-in-field-validators).
99

10-
For instance, with API Platform Core as backend, if you write the following:
10+
For instance, with API Platform as backend, if you write the following:
1111

1212
```php
1313
<?php
@@ -37,7 +37,7 @@ API Platform Admin will automatically show the errors for the corresponding fiel
3737
To do so, it uses the [submission validation](https://marmelab.com/react-admin/CreateEdit.html#submission-validation) feature of React Admin,
3838
and the mapping between the response and the fields is done by the [schema analyzer](components.md#schemaanalyzer) with its method `getSubmissionErrors`.
3939

40-
API Platform Core is supported by default, but if you use another backend, you will need to override the `getSubmissionErrors` method.
40+
API Platform is supported by default, but if you use another backend, you will need to override the `getSubmissionErrors` method.
4141

4242
For example if you have this code:
4343

core/content-negotiation.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The API system has built-in [content negotiation](https://en.wikipedia.org/wiki/Content_negotiation) capabilities.
44

5-
By default, only the [JSON-LD](https://json-ld.org) and JSON formats are enabled. However API Platform Core supports many more formats and can be extended.
5+
By default, only the [JSON-LD](https://json-ld.org) and JSON formats are enabled. However API Platform supports many more formats and can be extended.
66

77
The framework natively supports JSON-LD (and Hydra), GraphQL, JSON:API, HAL, YAML, CSV, HTML (API docs), raw JSON and raw XML.
88
Using the raw JSON or raw XML formats is discouraged, prefer using JSON-LD instead, which provides more feature and is as easy to use.
@@ -11,7 +11,7 @@ API Platform also supports [JSON Merge Patch (RFC 7396)](https://tools.ietf.org/
1111

1212
<p align="center" class="symfonycasts"><a href="https://symfonycasts.com/screencast/api-platform/formats?cid=apip"><img src="../distribution/images/symfonycasts-player.png" alt="Formats screencast"><br>Watch the Formats screencast</a></p>
1313

14-
API Platform Core will automatically detect the best resolving format depending on:
14+
API Platform will automatically detect the best resolving format depending on:
1515

1616
* enabled formats (see below)
1717
* the requested format, specified in either [the `Accept` HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept) or as an extension appended to the URL
@@ -133,10 +133,11 @@ use ApiPlatform\Metadata\Patch;
133133
use ApiPlatform\Metadata\GetCollection;
134134
use ApiPlatform\Metadata\Post;
135135
136-
#[ApiResource(formats: ['jsonld', 'csv' => ['text/csv']])]
137-
#[Patch(inputFormats: ['json' => ['application/merge-patch+json']])]
138-
#[GetCollection]
139-
#[Post]
136+
#[ApiResource(formats: ['jsonld', 'csv' => ['text/csv']], operations: [
137+
new Patch(inputFormats: ['json' => ['application/merge-patch+json']]),
138+
new GetCollection(),
139+
new Post(),
140+
])]
140141
class Book
141142
{
142143
// ...
@@ -195,7 +196,7 @@ api_platform:
195196
myformat: ['application/vnd.myformat']
196197
```
197198

198-
API Platform Core will automatically call the serializer with your defined format name as `format` parameter during the deserialization process (`myformat` in the example).
199+
API Platform will automatically call the serializer with your defined format name as `format` parameter during the deserialization process (`myformat` in the example).
199200
It will then return the result to the client with the requested MIME type using its built-in responder.
200201
For non-standard formats, [a vendor, vanity or unregistered MIME type should be used](https://en.wikipedia.org/wiki/Media_type#Vendor_tree).
201202

@@ -297,4 +298,4 @@ class CustomItemNormalizer implements NormalizerInterface, DenormalizerInterface
297298
### Contributing Support for New Formats
298299

299300
Adding support for **standard** formats upstream is welcome!
300-
We'll be glad to merge new encoders and normalizers in API Platform Core.
301+
We'll be glad to merge new encoders and normalizers in API Platform.

core/controllers.md

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ controller classes (the default when using the API Platform distribution).
6464
This action will be automatically registered as a service (the service name is the same as the class name:
6565
`App\Controller\CreateBookPublication`).
6666

67-
API Platform automatically retrieves the appropriate PHP entity using the data provider then deserializes user data in it,
68-
and for `POST`, `PUT` and `PATCH` requests updates the entity with data provided by the user.
67+
API Platform automatically retrieves the appropriate PHP entity using the state provider then deserializes user data in it,
68+
and for `POST`, `PUT` and `PATCH` requests updates the entity with state provided by the user.
6969

7070
The entity is retrieved in the `__invoke` method thanks to a dedicated argument resolver.
7171

@@ -97,13 +97,14 @@ use ApiPlatform\Metadata\Get;
9797
use ApiPlatform\Metadata\Post;
9898
use App\Controller\CreateBookPublication;
9999

100-
#[ApiResource]
101-
#[Get]
102-
#[Post(
103-
name: 'publication',
104-
uriTemplate: '/books/{id}/publication',
105-
controller: CreateBookPublication::class
106-
)]
100+
#[ApiResource(operations: [
101+
new Get(),
102+
new Post(
103+
name: 'publication',
104+
uriTemplate: '/books/{id}/publication',
105+
controller: CreateBookPublication::class
106+
)
107+
])]
107108
class Book
108109
{
109110
// ...
@@ -163,14 +164,15 @@ use ApiPlatform\Metadata\Post;
163164
use App\Controller\CreateBookPublication;
164165
use Symfony\Component\Serializer\Annotation\Groups;
165166

166-
#[ApiResource]
167-
#[Get]
168-
#[Post(
169-
name: 'publication',
170-
uriTemplate: '/books/{id}/publication',
171-
controller: CreateBookPublication::class,
172-
normalizationContext: ['groups' => 'publication']
173-
)]
167+
#[ApiResource(operations: [
168+
new Get(),
169+
new Post(
170+
name: 'publication',
171+
uriTemplate: '/books/{id}/publication',
172+
controller: CreateBookPublication::class,
173+
normalizationContext: ['groups' => 'publication']
174+
)
175+
])]
174176
class Book
175177
{
176178
// ...
@@ -238,14 +240,15 @@ use ApiPlatform\Metadata\Get;
238240
use ApiPlatform\Metadata\Post;
239241
use App\Controller\CreateBookPublication;
240242

241-
#[ApiResource]
242-
#[Get]
243-
#[Post(
244-
name: 'publication',
245-
uriTemplate: '/books/{id}/publication',
246-
controller: CreateBookPublication::class,
247-
read: false
248-
)]
243+
#[ApiResource(operations: [
244+
new Get(),
245+
new Post(
246+
name: 'publication',
247+
uriTemplate: '/books/{id}/publication',
248+
controller: CreateBookPublication::class,
249+
read: false
250+
)
251+
])]
249252
class Book
250253
{
251254
// ...
@@ -313,10 +316,11 @@ use ApiPlatform\Metadata\ApiResource;
313316
use ApiPlatform\Metadata\Get;
314317
use ApiPlatform\Metadata\Post;
315318

316-
#[ApiResource]
317-
#[Get]
318-
#[Post(name: 'publication', routeName: 'book_post_publication')]
319-
#[Post(name: 'book_post_discontinuation')]
319+
#[ApiResource(operations: [
320+
new Get(),
321+
new Post(name: 'publication', routeName: 'book_post_publication'),
322+
new Post(name: 'book_post_discontinuation')
323+
])]
320324
class Book
321325
{
322326
// ...

0 commit comments

Comments
 (0)