Skip to content

Commit 7208d97

Browse files
committed
Update all service configs according to changes in 2.1
1 parent 7f5b96b commit 7208d97

File tree

6 files changed

+50
-38
lines changed

6 files changed

+50
-38
lines changed

core/content-negotiation.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,15 @@ own implementation of `CustomItemNormalizer`:
7878
```yaml
7979
# app/config/services.yml
8080
81+
# ...
82+
8183
services:
82-
app.custom_item_normalizer:
83-
public: false
84-
class: AppBundle\Serializer\CustomItemNormalizer
84+
85+
# ...
86+
87+
'AppBundle\Serializer\CustomItemNormalizer':
8588
arguments: [ '@api_platform.serializer.normalizer.item' ]
86-
tags: [ { name: serializer.normalizer } ]
89+
tags: [ 'serializer.normalizer' ]
8790
```
8891

8992
```php

core/data-providers.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ Then declare a Symfony service, for example:
5858
# app/config/services.yml
5959

6060
services:
61-
blog_post.collection_data_provider:
62-
class: 'AppBundle\DataProvider\BlogPostCollectionDataProvider'
63-
public: false
64-
tags:
65-
- { name: 'api_platform.collection_data_provider', priority: 2 }
61+
62+
# ...
63+
64+
'AppBundle\DataProvider\BlogPostCollectionDataProvider':
65+
tags: [ { name: 'api_platform.collection_data_provider', priority: 2 } ]
6666
```
6767
6868
Tagging the service with the tag `api_platform.collection_data_provider` will enable API Platform Core to automatically
@@ -101,18 +101,21 @@ final class BlogPostItemDataProvider implements ItemDataProviderInterface
101101
}
102102
```
103103

104-
The tag to use for item data providers is `api_platform.item_data_provider`. As for collection data providers, the `priority`
105-
attribute can be used to order providers.
104+
If service autowiring and autoconfiguration are enabled (it's the case by default), you are done!
105+
106+
Otherwise, if you use a custom dependency injection configuration, you need to register the corresponding service add the
107+
`api_platform.item_data_provider` tag. As for collection data providers, the `priority` attribute can be used to order
108+
providers.
106109

107110
```yaml
108111
# app/config/services.yml
109112
110113
services:
111-
blog_post.item_data_provider:
112-
class: 'AppBundle\DataProvider\BlogPostItemDataProvider'
113-
public: false
114-
tags:
115-
- { name: 'api_platform.item_data_provider' }
114+
115+
# ...
116+
117+
'AppBundle\DataProvider\BlogPostItemDataProvider':
118+
tags: [ 'api_platform.item_data_provider' ]
116119
```
117120

118121
Previous chapter: [Extending JSON-LD context](extending-jsonld-context.md)

core/form-data.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ final class DeserializeListener
7676
# app/config/services.yml
7777

7878
services:
79+
7980
# ...
80-
app.listener.decorating_deserialize:
81-
class: 'AppBundle\EventListener\DeserializeListener'
82-
arguments: ['@api_platform.serializer', '@api_platform.serializer.context_builder', '@api_platform.listener.request.deserialize']
81+
82+
'AppBundle\EventListener\DeserializeListener':
8383
tags:
8484
- { name: 'kernel.event_listener', event: 'kernel.request', method: 'onKernelRequest', priority: 2 }
8585
```

core/serialization-groups-and-relations.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,12 @@ API Platform implements a `ContextBuilder`, which prepares the context for seria
300300
# app/config/services.yml
301301

302302
services:
303-
app.serializer.builder.book:
304-
decorates: api_platform.serializer.context_builder
305-
class: AppBundle\Serializer\BookContextBuilder
306-
arguments: ['@app.serializer.builder.book.inner', '@security.authorization_checker']
303+
304+
# ...
305+
306+
'AppBundle\Serializer\BookContextBuilder':
307+
decorates: 'api_platform.serializer.context_builder'
308+
arguments: [ '@app.serializer.builder.book.inner' ]
307309
```
308310
309311
```php
@@ -357,16 +359,17 @@ To use this feature, declare a new service with id `app.name_converter`. For exa
357359
# app/config/services.yml
358360

359361
services:
360-
app.name_converter:
361-
class: Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter
362-
public: false
362+
363+
# ...
364+
365+
'Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter': ~
363366
```
364367
365368
```yaml
366369
# app/config/config.yml
367370

368371
api_platform:
369-
name_converter: app.name_converter
372+
name_converter: 'Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter'
370373
```
371374
372375
## Entity Identifier Case

core/serialization.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ In the following example, we will see how we add extra informations to the outpu
3535
Here is how we add the date on each request in `GET`:
3636

3737
```yaml
38-
# app/config/services.yml
38+
# app/config/services.yml
3939

4040
services:
41-
app.custom.jsonld.normalizer_decorator:
42-
decorates: api_platform.jsonld.normalizer.item
43-
class: AppBundle\Serializer\ApiNormalizer
44-
autowire: true
41+
42+
# ...
43+
44+
'AppBundle\Serializer\ApiNormalizer':
45+
decorates: 'api_platform.jsonld.normalizer.item'
4546
```
4647
4748
```php

core/swagger.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ Symfony allows to [decorate services](https://symfony.com/doc/current/service_co
77
In the following example, we will see how to override the title of the Swagger documentation and add a custom filter for the `GET` operation of `/foos` path
88

99
```yaml
10-
# app/config/services.yml
11-
10+
# app/config/services.yml
11+
1212
services:
13-
app.swagger.swagger_decorator:
14-
decorates: api_platform.swagger.normalizer.documentation
15-
class: 'AppBundle\Swagger\SwaggerDecorator'
16-
arguments: ['@app.swagger.swagger_decorator.inner']
13+
14+
# ...
15+
16+
'AppBundle\Swagger\SwaggerDecorator':
17+
decorates: 'api_platform.swagger.normalizer.documentation'
18+
arguments: [ '@app.swagger.swagger_decorator.inner' ]
1719
```
1820
1921
```php

0 commit comments

Comments
 (0)