Skip to content

Commit 67f398f

Browse files
committed
Merge 3.2
2 parents 4072445 + 6f7af13 commit 67f398f

24 files changed

+927
-376
lines changed

core/bootstrap.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use ApiPlatform\JsonLd\Serializer\ObjectNormalizer as JsonLdObjectNormalizer;
5757
use ApiPlatform\JsonLd\ContextBuilder as JsonLdContextBuilder;
5858
use ApiPlatform\JsonSchema\SchemaFactory;
5959
use ApiPlatform\JsonSchema\TypeFactory;
60+
use ApiPlatform\Metadata\ApiResource;
6061
use ApiPlatform\Metadata\CollectionOperationInterface;
6162
use ApiPlatform\Metadata\HttpOperation;
6263
use ApiPlatform\Metadata\Operation;
@@ -257,7 +258,7 @@ $providerCollection = new class implements ContainerInterface {
257258
}
258259

259260
public function has($id): bool {
260-
return isset($this->providers['id']);
261+
return isset($this->providers[$id]);
261262
}
262263
};
263264
$stateProviders = new CallableProvider($providerCollection);
@@ -289,6 +290,12 @@ class Validator implements ValidatorInterface {
289290
$validator = new Validator(Validation::createValidator());
290291
$validateListener = new ValidateListener($validator, $resourceMetadataFactory);
291292

293+
#[ApiResource(provider: \BookProvider::class)]
294+
class Book
295+
{
296+
public int $id;
297+
}
298+
292299
class BookProvider implements ProviderInterface
293300
{
294301
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null

core/content-negotiation.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ this configuration might disable the `json` or the `html` on this resource for e
121121

122122
You can specify different accepted formats at operation level too, it's especially convenient to configure formats available for the `PATCH` method:
123123

124-
[codeSelector]
124+
<code-selector>
125125

126126
```php
127127
<?php
@@ -178,7 +178,7 @@ resources:
178178
</resources>
179179
```
180180

181-
[/codeSelector]
181+
</code-selector>
182182

183183
## Supporting Custom Formats
184184

@@ -237,9 +237,9 @@ final class CustomItemNormalizer implements NormalizerInterface, DenormalizerInt
237237
$this->normalizer = $normalizer;
238238
}
239239
240-
public function denormalize($data, $class, $format = null, array $context = [])
240+
public function denormalize($data, $type, $format = null, array $context = [])
241241
{
242-
return $this->normalizer->denormalize($data, $class, $format, $context);
242+
return $this->normalizer->denormalize($data, $type, $format, $context);
243243
}
244244
245245
public function supportsDenormalization($data, $type, $format = null)

core/controllers.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ the client.
8585

8686
The routing has not been configured yet because we will add it at the resource configuration level:
8787

88-
[codeSelector]
88+
<code-selector>
8989

9090
```php
9191
<?php
@@ -143,7 +143,7 @@ resources:
143143
</resources>
144144
```
145145

146-
[/codeSelector]
146+
</code-selector>
147147

148148
It is mandatory to set the `method`, `uriTemplate` and `controller` attributes. They allow API Platform to configure the routing path and
149149
the associated controller respectively.
@@ -158,7 +158,7 @@ To avoid that, API Platform provides the `ApiPlatform\Action\PlaceholderAction`
158158

159159
You just need to set the `controller` attribute with this class. Here, the previous example updated:
160160

161-
[codeSelector]
161+
<code-selector>
162162

163163
```php
164164
// api/src/Entity/Book.php
@@ -215,13 +215,13 @@ resources:
215215
</resources>
216216
```
217217

218-
[/codeSelector]
218+
</code-selector>
219219

220220
## Using Serialization Groups
221221

222222
You may want different serialization groups for your custom operations. Just configure the proper `normalizationContext` and/or `denormalizationContext` in your operation:
223223

224-
[codeSelector]
224+
<code-selector>
225225

226226
```php
227227
<?php
@@ -292,14 +292,14 @@ resources:
292292
</resources>
293293
```
294294

295-
[/codeSelector]
295+
</code-selector>
296296

297297
## Retrieving the Entity
298298

299299
If you want to bypass the automatic retrieval of the entity in your custom operation, you can set `read: false` in the
300300
operation attribute:
301301

302-
[codeSelector]
302+
<code-selector>
303303

304304
```php
305305
<?php
@@ -357,7 +357,7 @@ resources:
357357
</resources>
358358
```
359359

360-
[/codeSelector]
360+
</code-selector>
361361

362362
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)
363363
for more information.
@@ -377,7 +377,7 @@ for `book_post_discontinuation` when neither `method` nor `routeName` attributes
377377

378378
First, let's create your resource configuration:
379379

380-
[codeSelector]
380+
<code-selector>
381381

382382
```php
383383
<?php
@@ -430,7 +430,7 @@ resources:
430430
</resources>
431431
```
432432

433-
[/codeSelector]
433+
</code-selector>
434434

435435
API Platform will automatically map this `post_publication` operation to the route `book_post_publication`. Let's create a custom action
436436
and its related route using attributes:

core/default-order.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ API Platform provides an easy way to override the default order of items in your
55
By default, items in the collection are ordered in ascending (ASC) order by their resource identifier(s). If you want to
66
customize this order, you must add an `order` attribute on your ApiResource annotation:
77

8-
[codeSelector]
8+
<code-selector>
99

1010
```php
1111
<?php
@@ -35,12 +35,12 @@ App\Entity\Book:
3535
foo: ASC
3636
```
3737
38-
[/codeSelector]
38+
</code-selector>
3939
4040
This `order` attribute is used as an array: the key defines the order field, the values defines the direction.
4141
If you only specify the key, `ASC` direction will be used as default. For example, to order by `foo` & `bar`:
4242

43-
[codeSelector]
43+
<code-selector>
4444

4545
```php
4646
<?php
@@ -74,11 +74,11 @@ App\Entity\Book:
7474
order: ['foo', 'bar']
7575
```
7676

77-
[/codeSelector]
77+
</code-selector>
7878

7979
It's also possible to configure the default order on an association property:
8080

81-
[codeSelector]
81+
<code-selector>
8282

8383
```php
8484
<?php
@@ -107,11 +107,11 @@ App\Entity\Book:
107107
order: ['author.username']
108108
```
109109

110-
[/codeSelector]
110+
</code-selector>
111111

112112
Another possibility is to apply the default order for a specific collection operation, which will override the global default order configuration.
113113

114-
[codeSelector]
114+
<code-selector>
115115

116116
```php
117117
<?php
@@ -155,4 +155,4 @@ App\Entity\Book:
155155
name: ASC
156156
```
157157

158-
[/codeSelector]
158+
</code-selector>

core/deprecations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Parchment
6767

6868
It's also possible to deprecate a single property:
6969

70-
[codeSelector]
70+
<code-selector>
7171

7272
```php
7373
<?php
@@ -99,7 +99,7 @@ properties:
9999
deprecationReason: 'Use the rating property instead'
100100
```
101101
102-
[/codeSelector]
102+
</code-selector>
103103
104104
* With JSON-lD / Hydra, [an `owl:deprecated` annotation property](https://www.w3.org/TR/owl2-syntax/#Annotation_Properties) will be added to the appropriate data structure
105105
* With Swagger / OpenAPI, [a `deprecated` property](https://swagger.io/docs/specification/2-0/paths-and-operations/) will be added

core/dto.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ final class BookRepresentationProvider implements ProviderInterface
124124

125125
For returning another representation of your data in a [State Processor](./state-processors.md), you should specify your processor class in the `processor` attribute and same for your `output`.
126126

127-
[codeSelector]
127+
<code-selector>
128128

129129
```php
130130
<?php
@@ -165,7 +165,7 @@ resources:
165165
</resources>
166166
```
167167

168-
[/codeSelector]
168+
</code-selector>
169169

170170
Here the `$data` attribute represents an instance of your resource.
171171

core/errors.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ API Platform automatically sends the appropriate HTTP status code to the client:
66
unexpected ones. It also provides a description of the error in [the Hydra error format](https://www.hydra-cg.com/spec/latest/core/#description-of-http-status-codes-and-errors)
77
or in the format described in the [RFC 7807](https://tools.ietf.org/html/rfc7807), depending of the format selected during the [content negotiation](content-negotiation.md).
88

9-
# Errors
10-
119
## Backward compatibility with < 3.1
1210

13-
Use the following configuration:
11+
Use the following configuration:
1412

1513
```yaml
1614
api_platform:
1715
defaults:
16+
extra_properties:
1817
rfc_7807_compliant_errors: false
1918
```
2019
21-
This can also be configured on an `ApiResource` or in an `HttpOperation`, for example:
20+
This can also be configured on an `ApiResource` or in an `HttpOperation`, for example:
2221

2322
```php
2423
#[ApiResource(extraProperties: ['rfc_7807_compliant_errors' => false])
@@ -31,10 +30,8 @@ There are many ways of configuring the exception status code we recommend readin
3130
1. we look at `exception_to_status` and take one if there's a match
3231
2. If your exception is a `Symfony\Component\HttpKernel\Exception\HttpExceptionInterface` we get its status.
3332
3. If the exception is a `ApiPlatform\Metadata\Exception\ProblemExceptionInterface` and there is a status we use it
34-
4. Same for `ApiPlatform\Metadata\Exception\HttpExceptionInterface`
35-
5. We have some defaults:
36-
- `Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface` => 400
37-
- `ApiPlatform\Validator\Exception\ValidationException` => 422
33+
4. Same for `ApiPlatform\Metadata\Exception\HttpExceptionInterface`
34+
5. We have some defaults `Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface` => 400 and `ApiPlatform\Validator\Exception\ValidationException` => 422
3835
6. the status defined on an `ErrorResource`
3936
7. 500 is the fallback
4037

@@ -175,9 +172,9 @@ the global config.
175172

176173
## Control your exceptions
177174

178-
With `rfc_7807_compliant_errors` a few things happen. First Hydra exception are compatible with the JSON Problem specification. Default exception that are handled by API Platform in JSON will be returned as `application/problem+json`.
175+
With `rfc_7807_compliant_errors` a few things happen. First Hydra exception are compatible with the JSON Problem specification. Default exception that are handled by API Platform in JSON will be returned as `application/problem+json`.
179176

180-
To customize the API Platform response, replace the `api_platform.state.error_provider` with your own provider:
177+
To customize the API Platform response, replace the `api_platform.state.error_provider` with your own provider:
181178

182179
```php
183180
<?php
@@ -234,7 +231,7 @@ api_platform.validator.state.error_provider:
234231

235232
## Domain exceptions
236233

237-
Another way of having full control over domain exceptions is to create your own Error resource:
234+
Another way of having full control over domain exceptions is to create your own Error resource:
238235

239236
```php
240237
<?php

core/events.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# The Event System
22

3+
In API Platform 3.2 you may need `event_listeners_backward_compatibility_layer: true` to keep event listeners activated.
4+
35
Note: using Kernel event with API Platform should be mostly limited to tweaking the generated HTTP response. Also, GraphQL is **not supported**.
46
[For most use cases, better extension points, working both with REST and GraphQL, are available](extending.md).
57

core/extending-jsonld-context.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Note that you do not have to provide the `@id` attribute. If you do not provide
6767

6868
It's also possible to replace the Hydra context used by the documentation generator:
6969

70-
[codeSelector]
70+
<code-selector>
7171

7272
```php
7373
<?php
@@ -117,4 +117,4 @@ resources:
117117
</resources>
118118
```
119119

120-
[/codeSelector]
120+
</code-selector>

0 commit comments

Comments
 (0)