Skip to content

Commit 5556156

Browse files
authored
Merge pull request #262 from dunglas/services-config
Update all service configs according to changes in 2.1
2 parents 233a111 + 33e6697 commit 5556156

12 files changed

+97
-86
lines changed

core/content-negotiation.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ and of a custom format called `myformat` and having `application/vnd.myformat` a
4444
# app/config/config.yml
4545

4646
api_platform:
47+
4748
# ...
49+
4850
formats:
4951
jsonld: ['application/ld+json']
5052
jsonhal: ['application/hal+json']
@@ -79,11 +81,12 @@ own implementation of `CustomItemNormalizer`:
7981
# app/config/services.yml
8082
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
@@ -96,7 +99,7 @@ namespace AppBundle\Serializer;
9699
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
97100
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
98101
99-
class CustomItemNormalizer implements NormalizerInterface, DenormalizerInterface
102+
final class CustomItemNormalizer implements NormalizerInterface, DenormalizerInterface
100103
{
101104
private $normalizer;
102105

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/extensions.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,10 @@ Finally register the custom extension:
122122
# app/config/services.yml
123123

124124
services:
125-
app.doctrine.orm.query_extension.current_user:
126-
class: AppBundle\Doctrine\ORM\Extension\CurrentUserExtension
127-
public: false
128-
arguments:
129-
- '@security.token_storage'
130-
- '@security.authorization_checker'
125+
126+
# ...
127+
128+
'AppBundle\Doctrine\ORM\Extension\CurrentUserExtension':
131129
tags:
132130
- { name: api_platform.doctrine.orm.query_extension.collection, priority: 9 }
133131
- { name: api_platform.doctrine.orm.query_extension.item }
@@ -147,10 +145,13 @@ To secure the access to endpoints, use the following access control rule:
147145
# app/config/security.yml
148146
149147
security:
148+
150149
# ...
151150
152151
access_control:
152+
153153
# ...
154+
154155
- { path: ^/offers, roles: IS_AUTHENTICATED_FULLY }
155156
- { path: ^/users, roles: IS_AUTHENTICATED_FULLY }
156157
```

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/nelmio-api-doc.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ To enable the NelmioApiDoc integration, copy the following configuration:
1212
# app/config/config.yml
1313

1414
api_platform:
15+
1516
# ...
17+
1618
enable_nelmio_api_doc: true
1719

1820
nelmio_api_doc:
1921
sandbox:
20-
accept_type: 'application/json'
22+
accept_type: 'application/json'
2123
body_format:
22-
formats: ['json']
24+
formats: ['json']
2325
default_format: 'json'
2426
request_format:
2527
formats:
26-
json: 'application/json'
28+
json: 'application/json'
2729
```
2830
2931
Please note that NelmioApiDocBundle has a sandbox limitation where you cannot pass a JSON array as parameter, so you cannot

core/operation-path-naming.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,27 @@ Note that `$resourceShortName` contains a camel case string, by default the reso
5959

6060
### Registering the Service
6161

62-
<configurations>
62+
If you haven't disabled the autowiring option, the service will be registered automatically and you have nothing more to
63+
do.
64+
Otherwise, you must register this class a service like in the following example:
6365

6466
```yaml
6567
# app/config/services.yml
6668
6769
services:
68-
app.operation_path_resolver.no_separators:
69-
class: 'AppBundle\\PathResolver\\NoSeparatorsOperationPathResolver'
70-
public: false
71-
```
7270
73-
```xml
74-
<!-- app/config/services.xml -->
71+
# ...
7572
76-
<?xml version="1.0" encoding="UTF-8" ?>
77-
<services>
78-
<service id="app.operation_path_resolver.no_separators" class="AppBundle\PathResolver\NoSeparatorsOperationPathResolver" public="false" />
79-
</services>
73+
'AppBundle\PathResolver\NoSeparatorsOperationPathResolver': ~
8074
```
8175

82-
</configurations>
83-
8476
### Configure It
8577

8678
```yaml
8779
# app/config/config.yml
8880
8981
api_platform:
90-
default_operation_path_resolver: 'app.operation_path_resolver.no_separators'
82+
default_operation_path_resolver: 'AppBundle\PathResolver\NoSeparatorsOperationPathResolver'
9183
```
9284

9385
Previous chapter: [Performance](performance.md)

core/performance.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,11 @@ little of configuration:
8383
# app/config/config.yaml
8484

8585
api_platform:
86+
8687
# ...
8788

8889
eager_loading:
8990
max_joins: 100
90-
91-
# ...
9291
```
9392
9493
Be careful when you exceed this limit, it's often caused by the result of a circular reference. [Serializer groups](serialization-groups-and-relations.md)
@@ -103,12 +102,11 @@ configuration in order to apply it only on join relations having the `EAGER` fet
103102
# app/config/config.yaml
104103
105104
api_platform:
105+
106106
# ...
107107
108108
eager_loading:
109109
force_eager: false
110-
111-
# ...
112110
```
113111

114112
#### Override at resource and operation level
@@ -212,12 +210,11 @@ If for any reason you don't want the eager loading feature, you can turn it off
212210
# app/config/config.yaml
213211
214212
api_platform:
213+
215214
# ...
216215
217216
eager_loading:
218217
enabled: false
219-
220-
# ...
221218
```
222219

223220
The whole configuration seen before will no longer work and Doctrine will recover its default behavior.

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: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
# Swagger Support
22

33
## Override Swagger documentation
4-
Symfony allows to [decorate services](https://symfony.com/doc/current/service_container/service_decoration.html), here we need to decorate
5-
`api_platform.swagger.normalizer.documentation`
4+
5+
Symfony allows to [decorate services](https://symfony.com/doc/current/service_container/service_decoration.html), here we
6+
need to decorate `api_platform.swagger.normalizer.documentation`.
7+
68
### Example
7-
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
9+
10+
In the following example, we will see how to override the title of the Swagger documentation and add a custom filter for
11+
the `GET` operation of `/foos` path
812

913
```yaml
10-
# app/config/services.yml
11-
14+
# app/config/services.yml
15+
1216
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']
17+
18+
# ...
19+
20+
'AppBundle\Swagger\SwaggerDecorator':
21+
decorates: 'api_platform.swagger.normalizer.documentation'
22+
arguments: [ '@app.swagger.swagger_decorator.inner' ]
1723
```
1824
1925
```php

deployment/heroku.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ file:
4949
"pre-install-cmd": [
5050
"Dunglas\\Heroku\\Database::createParameters"
5151
],
52-
// ...
52+
"_": "..."
5353
}
5454
```
5555

@@ -115,23 +115,27 @@ persist applications logs. To use it we need to configure Monolog to output logs
115115
Open `app/config/config_prod.yml`, find the following block:
116116

117117
```yaml
118-
monolog:
119-
# ...
120-
nested:
121-
type: stream
122-
path: "%kernel.logs_dir%/%kernel.environment%.log"
123-
level: debug
118+
monolog:
119+
120+
# ...
121+
122+
nested:
123+
type: stream
124+
path: '%kernel.logs_dir%/%kernel.environment%.log'
125+
level: debug
124126
```
125127

126128
And replace it by:
127129

128130
```yaml
129-
monolog:
130-
# ...
131-
nested:
132-
type: stream
133-
path: "php://stderr"
134-
level: debug
131+
monolog:
132+
133+
# ...
134+
135+
nested:
136+
type: stream
137+
path: 'php://stderr'
138+
level: debug
135139
```
136140

137141
We are ready to deploy our app!
@@ -165,8 +169,6 @@ can scale it in one click from the Heroku interface.
165169

166170
To see your logs, run `heroku logs --tail`.
167171

168-
Can it be easier? Yes it can: we are preparing an API Platform edition preconfigured to run on Heroku! Stay tuned.
169-
170172
Previous chapter: [Introduction](index.md)
171173

172174
Next chapter: [Using API Platform with Docker](docker.md)

schema-generator/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ rdfa:
446446
types:
447447
Session:
448448
vocabularyNamespace: http://purl.org/net/VideoGameOntology#
449+
449450
# ...
450451
```
451452

0 commit comments

Comments
 (0)