Skip to content

Commit efcdce5

Browse files
committed
Merge remote-tracking branch 'upstream/2.6'
2 parents c494b63 + 86d71dd commit efcdce5

File tree

11 files changed

+72
-149
lines changed

11 files changed

+72
-149
lines changed

client-generator/react-native.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
To use this generator you need [Node.js](https://nodejs.org/) and [Yarn](https://yarnpkg.com/) (or [npm](https://www.npmjs.com/)) installed.
88
To run the command line tool, we also recommend using [npx](https://www.npmjs.com/package/npx).
99

10-
Create a React Native application using [Expo CLI](https://docs.expo.io/versions/latest/workflow/expo-cli).
10+
Create a React Native application using [Expo CLI](https://docs.expo.io/workflow/expo-cli/).
1111

1212
```console
1313
yarn global add expo-cli

client-generator/vuetify.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ The generator comes with a i18n feature to allow quick translations of some labe
150150
work, you need to create this file:
151151

152152
```javascript
153-
// src/plugins/vuetify.js
153+
// src/i18n.js
154154
import Vue from 'vue';
155155
import VueI18n from 'vue-i18n';
156156
import messages from './locales/en';
@@ -210,10 +210,10 @@ Update your App.vue:
210210
<v-toolbar-title>Application</v-toolbar-title>
211211
</v-app-bar>
212212
213-
<v-content>
213+
<v-main>
214214
<Breadcrumb layout-class="pl-3 py-3" />
215215
<router-view></router-view>
216-
</v-content>
216+
</v-main>
217217
<v-footer color="indigo" app>
218218
<span class="white--text">&copy; 2019</span>
219219
</v-footer>

core/controllers.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ This action will be automatically registered as a service (the service name is t
6666
`App\Controller\CreateBookPublication`).
6767

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

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

@@ -289,6 +289,9 @@ App\Entity\Book:
289289
This way, it will skip the `ReadListener`. You can do the same for some other built-in listeners. See [Built-in Event Listeners](events.md#built-in-event-listeners)
290290
for more information.
291291

292+
In your custom controller, the `__invoke()` method parameter should be called the same as the entity identifier.
293+
So for the path `/user/{uuid}/bookmarks`, you must use `__invoke(string $uuid)`.
294+
292295
## Alternative Method
293296

294297
There is another way to create a custom operation. However, we do not encourage its use. Indeed, this one disperses

core/dto.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ services:
203203

204204
## Updating a Resource with a Custom Input
205205

206-
When performing an update (e.g. `PUT` operation), the resource to be updated is read by ApiPlatform before the deserialization phase. To do so, it uses a [data provider](data-providers.md) with the `:id` parameter given in the URL. The *body* of the request is the JSON object sent by the client, it is deserialized and is used to update the previously found resource.
206+
When performing an update (e.g. `PUT` operation), the resource to be updated is read by API Platform before the deserialization phase.
207+
To do so, it uses a [data provider](data-providers.md) with the `:id` parameter given in the URL.
208+
The *body* of the request is the JSON object sent by the client, it is deserialized and is used to update the previously found resource.
207209

208210
![Diagram put input output](images/diagrams/api-platform-put-i-o.svg)
209211

core/events.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ are also available if you want to hook into the persistence layer's object lifec
2222

2323
These built-in event listeners are registered for routes managed by API Platform:
2424

25-
Name | Event | [Pre & Post hooks](#custom-event-listeners) | Priority | Description
26-
---------------------------------|--------------------|---------------------------------------------|----------|-------------
27-
`AddFormatListener` | `kernel.request` | None | 28 | Guesses the best response format ([content negotiation](content-negotiation.md))
25+
Name | Event | [Pre & Post hooks](#custom-event-listeners) | Priority | Description
26+
------------------------------|--------------------|---------------------------------------------|----------|-------------
27+
`AddFormatListener` | `kernel.request` | None | 7 | Guesses the best response format ([content negotiation](content-negotiation.md))
2828
`QueryParameterValidateListener` | `kernel.request` | None | 16 | Validates query parameters
29-
`ReadListener` | `kernel.request` | `PRE_READ`, `POST_READ` | 4 | Retrieves data from the persistence system using the [data providers](data-providers.md) (`GET`, `PUT`, `DELETE`)
30-
`DeserializeListener` | `kernel.request` | `PRE_DESERIALIZE`, `POST_DESERIALIZE` | 2 | Deserializes data into a PHP entity (`GET`, `POST`, `DELETE`); updates the entity retrieved using the data provider (`PUT`)
31-
`DenyAccessListener` | `kernel.request` | None | 1 | Enforces [access control](security.md) using Security expressions
32-
`ValidateListener` | `kernel.view` | `PRE_VALIDATE`, `POST_VALIDATE` | 64 | [Validates data](validation.md) (`POST`, `PUT`)
33-
`WriteListener` | `kernel.view` | `PRE_WRITE`, `POST_WRITE` | 32 | Persists changes in the persistence system using the [data persisters](data-persisters.md) (`POST`, `PUT`, `DELETE`)
34-
`SerializeListener` | `kernel.view` | `PRE_SERIALIZE`, `POST_SERIALIZE` | 16 | Serializes the PHP entity in string [according to the request format](content-negotiation.md)
35-
`RespondListener` | `kernel.view` | `PRE_RESPOND`, `POST_RESPOND` | 8 | Transforms serialized to a `Symfony\Component\HttpFoundation\Response` instance
36-
`AddLinkHeaderListener` | `kernel.response` | None | 0 | Adds a `Link` HTTP header pointing to the Hydra documentation
37-
`ValidationExceptionListener` | `kernel.exception` | None | 0 | Serializes validation exceptions in the Hydra format
38-
`ExceptionListener` | `kernel.exception` | None | -96 | Serializes PHP exceptions in the Hydra format (including the stack trace in debug mode)
29+
`ReadListener` | `kernel.request` | `PRE_READ`, `POST_READ` | 4 | Retrieves data from the persistence system using the [data providers](data-providers.md) (`GET`, `PUT`, `PATCH`, `DELETE`)
30+
`DeserializeListener` | `kernel.request` | `PRE_DESERIALIZE`, `POST_DESERIALIZE` | 2 | Deserializes data into a PHP entity (`GET`, `POST`, `DELETE`); updates the entity retrieved using the data provider (`PUT`, `PATCH`)
31+
`DenyAccessListener` | `kernel.request` | None | 1 | Enforces [access control](security.md) using Security expressions
32+
`ValidateListener` | `kernel.view` | `PRE_VALIDATE`, `POST_VALIDATE` | 64 | [Validates data](validation.md) (`POST`, `PUT`, `PATCH`)
33+
`WriteListener` | `kernel.view` | `PRE_WRITE`, `POST_WRITE` | 32 | Persists changes in the persistence system using the [data persisters](data-persisters.md) (`POST`, `PUT`, `PATCH`, `DELETE`)
34+
`SerializeListener` | `kernel.view` | `PRE_SERIALIZE`, `POST_SERIALIZE` | 16 | Serializes the PHP entity in string [according to the request format](content-negotiation.md)
35+
`RespondListener` | `kernel.view` | `PRE_RESPOND`, `POST_RESPOND` | 8 | Transforms serialized to a `Symfony\Component\HttpFoundation\Response` instance
36+
`AddLinkHeaderListener` | `kernel.response` | None | 0 | Adds a `Link` HTTP header pointing to the Hydra documentation
37+
`ValidationExceptionListener` | `kernel.exception` | None | 0 | Serializes validation exceptions in the Hydra format
38+
`ExceptionListener` | `kernel.exception` | None | -96 | Serializes PHP exceptions in the Hydra format (including the stack trace in debug mode)
3939

4040
Some of these built-in listeners can be enabled/disabled by setting operation attributes:
4141

core/filters.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,7 @@ class DummyCar
16271627
/**
16281628
* @ORM\Column(type="string")
16291629
*/
1630-
#[ApiFilter(SearchFilter::class, strategy => 'partial')]
1630+
#[ApiFilter(SearchFilter::class, strategy: 'partial')]
16311631
public $name;
16321632
16331633
/**
@@ -1643,7 +1643,7 @@ class DummyCar
16431643
On the first property, `name`, it's straightforward. The first annotation argument is the filter class, the second specifies options, here, the strategy:
16441644

16451645
```php
1646-
#[ApiFilter(SearchFilter::class, strategy => 'partial')]
1646+
#[ApiFilter(SearchFilter::class, strategy: 'partial')]
16471647
```
16481648

16491649
In the second annotation, we specify `properties` on which the filter should apply. It's necessary here because we don't want to filter `colors` but the `prop` property of the `colors` association.
@@ -1674,7 +1674,7 @@ use Doctrine\ORM\Mapping as ORM;
16741674
16751675
#[ApiResource]
16761676
#[ApiFilter(BooleanFilter::class)]
1677-
#[ApiFilter(DateFilter::class, strategy => DateFilter::EXCLUDE_NULL)]
1677+
#[ApiFilter(DateFilter::class, strategy: DateFilter::EXCLUDE_NULL)]
16781678
#[ApiFilter(SearchFilter::class, properties: ['colors.prop' => 'ipartial', 'name' => 'partial'])]
16791679
#[ApiFilter(PropertyFilter::class, arguments: ['parameterName' => 'foobar'])]
16801680
#[ApiFilter(GroupFilter::class, arguments: ['parameterName' => 'foobargroups'])]
@@ -1694,7 +1694,7 @@ The `BooleanFilter` is applied to every `Boolean` property of the class. Indeed,
16941694
The `DateFilter` given here will be applied to every `Date` property of the `DummyCar` class with the `DateFilter::EXCLUDE_NULL` strategy:
16951695

16961696
```php
1697-
#[ApiFilter(DateFilter::class, strategy => DateFilter::EXCLUDE_NULL)]
1697+
#[ApiFilter(DateFilter::class, strategy: DateFilter::EXCLUDE_NULL)]
16981698
```
16991699

17001700
The `SearchFilter` here adds properties. The result is the exact same as the example with annotations on properties:

core/operations.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Note: the `PATCH` method must be enabled explicitly in the configuration, refer
4444

4545
Note: with JSON Merge Patch, the [null values will be skipped](https://symfony.com/doc/current/components/serializer.html#skipping-null-values) in the response.
4646

47+
Note: Current `PUT` implementation behaves more or less like the `PATCH` method. Existing properties not included in the payload are **not** removed, their current values are preserved. To remove an existing property, its value must be explicitly set to `null`. Implementing [the standard `PUT` behavior](https://httpwg.org/specs/rfc7231.html#PUT) is on the roadmap, follow [issue #4344] (https://github.com/api-platform/core/issues/4344) to track the progress.
48+
4749
## Enabling and Disabling Operations
4850

4951
If no operation is specified, all default CRUD operations are automatically registered. It is also possible - and recommended
@@ -213,7 +215,7 @@ App\Entity\Book:
213215
get: ~
214216
itemOperations:
215217
get:
216-
controller: App\Controller\NotFoundAction
218+
controller: ApiPlatform\Core\Action\NotFoundAction
217219
read: false
218220
output: false
219221
```
@@ -232,7 +234,7 @@ App\Entity\Book:
232234
</collectionOperations>
233235
<itemOperations>
234236
<itemOperation name="get">
235-
<attribute name="controller">App\Controller\NotFoundAction</attribute>
237+
<attribute name="controller">ApiPlatform\Core\Action\NotFoundAction</attribute>
236238
<attribute name="read">false</attribute>
237239
<attribute name="output">false</attribute>
238240
</itemOperation>
@@ -598,7 +600,7 @@ class Weather
598600
// ...
599601
```
600602

601-
This will expose the `Weather` model, but also all the default CRUD routes: `GET`, `PUT`, `DELETE` and `POST`, which is a non-sense in our context.
603+
This will expose the `Weather` model, but also all the default CRUD routes: `GET`, `PUT`, `PATCH`, `DELETE` and `POST`, which is a non-sense in our context.
602604
Since we are required to expose at least one route, let's expose just one:
603605

604606
```php

core/security.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ class Book
102102
App\Entity\Book:
103103
properties:
104104
adminOnlyProperty:
105-
security: 'is_granted("ROLE_ADMIN")'
105+
attributes:
106+
security: 'is_granted("ROLE_ADMIN")'
106107
```
107108
108109
[/codeSelector]
@@ -123,7 +124,7 @@ Available variables are:
123124
* `request`: the current request
124125

125126
Access control checks in the `security` attribute are always executed before the [denormalization step](serialization.md).
126-
It means than for `PUT` requests, `object` doesn't contain the value submitted by the user, but values currently stored in [the persistence layer](data-persisters.md).
127+
It means than for `PUT` or `PATCH` requests, `object` doesn't contain the value submitted by the user, but values currently stored in [the persistence layer](data-persisters.md).
127128

128129
## Executing Access Control Rules After Denormalization
129130

core/serialization.md

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Alternatively, you can use the more verbose syntax:
139139
```
140140

141141
In the previous example, the `name` property will be visible when reading (`GET`) the object, and it will also be available
142-
to write (`PUT/POST`). The `author` property will be write-only; it will not be visible when serialized responses are
142+
to write (`PUT` / `PATCH` / `POST`). The `author` property will be write-only; it will not be visible when serialized responses are
143143
returned by the API.
144144

145145
Internally, API Platform passes the value of the `normalization_context` as the 3rd argument of [the `Serializer::serialize()` method](https://api.symfony.com/master/Symfony/Component/Serializer/SerializerInterface.html#method_serialize) during the normalization
@@ -252,7 +252,8 @@ In the following JSON document, the relation from a book to an author is by defa
252252

253253
It is possible to embed related objects (in their entirety, or only some of their properties) directly in the parent
254254
response through the use of serialization groups. By using the following serialization groups annotations (`@Groups`),
255-
a JSON representation of the author is embedded in the book response:
255+
a JSON representation of the author is embedded in the book response. As soon as any of the author's attributes is in
256+
the `book` group, the author will be embedded.
256257

257258
[codeSelector]
258259

@@ -282,6 +283,26 @@ class Book
282283
}
283284
```
284285

286+
```yaml
287+
# api/config/api_platform/resources/Book.yaml
288+
App\Entity\Book:
289+
attributes:
290+
normalization_context:
291+
groups: ['book']
292+
293+
# api/config/serializer/Book.yaml
294+
App\Entity\Book:
295+
attributes:
296+
name:
297+
groups: ['book']
298+
author:
299+
groups: ['book']
300+
```
301+
302+
[/codeSelector]
303+
304+
[codeSelector]
305+
285306
```php
286307
<?php
287308
// api/src/Entity/Person.php
@@ -305,20 +326,6 @@ class Person
305326
```
306327

307328
```yaml
308-
# api/config/api_platform/resources/Book.yaml
309-
App\Entity\Book:
310-
attributes:
311-
normalization_context:
312-
groups: ['book']
313-
314-
# api/config/serializer/Book.yaml
315-
App\Entity\Book:
316-
attributes:
317-
name:
318-
groups: ['book']
319-
author:
320-
groups: ['book']
321-
322329
# api/config/serializer/Person.yaml
323330
App\Entity\Person:
324331
attributes:
@@ -352,7 +359,7 @@ Instead of embedding relations in the main HTTP response, you may want [to "push
352359

353360
### Denormalization
354361

355-
It is also possible to embed a relation in `PUT` and `POST` requests. To enable that feature, set the serialization groups
362+
It is also possible to embed a relation in `PUT`, `PATCH` and `POST` requests. To enable that feature, set the serialization groups
356363
the same way as normalization. For example:
357364

358365
[codeSelector]

0 commit comments

Comments
 (0)