Skip to content

Update all service configs according to changes in 2.1 #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions core/content-negotiation.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ and of a custom format called `myformat` and having `application/vnd.myformat` a
# app/config/config.yml

api_platform:

# ...

formats:
jsonld: ['application/ld+json']
jsonhal: ['application/hal+json']
Expand Down Expand Up @@ -79,11 +81,12 @@ own implementation of `CustomItemNormalizer`:
# app/config/services.yml

services:
app.custom_item_normalizer:
public: false
class: AppBundle\Serializer\CustomItemNormalizer

# ...

'AppBundle\Serializer\CustomItemNormalizer':
arguments: [ '@api_platform.serializer.normalizer.item' ]
tags: [ { name: serializer.normalizer } ]
tags: [ 'serializer.normalizer' ]
```

```php
Expand All @@ -96,7 +99,7 @@ namespace AppBundle\Serializer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class CustomItemNormalizer implements NormalizerInterface, DenormalizerInterface
final class CustomItemNormalizer implements NormalizerInterface, DenormalizerInterface
{
private $normalizer;

Expand Down
27 changes: 15 additions & 12 deletions core/data-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ Then declare a Symfony service, for example:
# app/config/services.yml

services:
blog_post.collection_data_provider:
class: 'AppBundle\DataProvider\BlogPostCollectionDataProvider'
public: false
tags:
- { name: 'api_platform.collection_data_provider', priority: 2 }

# ...

'AppBundle\DataProvider\BlogPostCollectionDataProvider':
tags: [ { name: 'api_platform.collection_data_provider', priority: 2 } ]
```

Tagging the service with the tag `api_platform.collection_data_provider` will enable API Platform Core to automatically
Expand Down Expand Up @@ -101,18 +101,21 @@ final class BlogPostItemDataProvider implements ItemDataProviderInterface
}
```

The tag to use for item data providers is `api_platform.item_data_provider`. As for collection data providers, the `priority`
attribute can be used to order providers.
If service autowiring and autoconfiguration are enabled (it's the case by default), you are done!

Otherwise, if you use a custom dependency injection configuration, you need to register the corresponding service add the
`api_platform.item_data_provider` tag. As for collection data providers, the `priority` attribute can be used to order
providers.

```yaml
# app/config/services.yml

services:
blog_post.item_data_provider:
class: 'AppBundle\DataProvider\BlogPostItemDataProvider'
public: false
tags:
- { name: 'api_platform.item_data_provider' }

# ...

'AppBundle\DataProvider\BlogPostItemDataProvider':
tags: [ 'api_platform.item_data_provider' ]
```

Previous chapter: [Extending JSON-LD context](extending-jsonld-context.md)
Expand Down
13 changes: 7 additions & 6 deletions core/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,10 @@ Finally register the custom extension:
# app/config/services.yml

services:
app.doctrine.orm.query_extension.current_user:
class: AppBundle\Doctrine\ORM\Extension\CurrentUserExtension
public: false
arguments:
- '@security.token_storage'
- '@security.authorization_checker'

# ...

'AppBundle\Doctrine\ORM\Extension\CurrentUserExtension':
tags:
- { name: api_platform.doctrine.orm.query_extension.collection, priority: 9 }
- { name: api_platform.doctrine.orm.query_extension.item }
Expand All @@ -147,10 +145,13 @@ To secure the access to endpoints, use the following access control rule:
# app/config/security.yml

security:

# ...

access_control:

# ...

- { path: ^/offers, roles: IS_AUTHENTICATED_FULLY }
- { path: ^/users, roles: IS_AUTHENTICATED_FULLY }
```
Expand Down
6 changes: 3 additions & 3 deletions core/form-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ final class DeserializeListener
# app/config/services.yml

services:

# ...
app.listener.decorating_deserialize:
class: 'AppBundle\EventListener\DeserializeListener'
arguments: ['@api_platform.serializer', '@api_platform.serializer.context_builder', '@api_platform.listener.request.deserialize']

'AppBundle\EventListener\DeserializeListener':
tags:
- { name: 'kernel.event_listener', event: 'kernel.request', method: 'onKernelRequest', priority: 2 }
```
Expand Down
8 changes: 5 additions & 3 deletions core/nelmio-api-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ To enable the NelmioApiDoc integration, copy the following configuration:
# app/config/config.yml

api_platform:

# ...

enable_nelmio_api_doc: true

nelmio_api_doc:
sandbox:
accept_type: 'application/json'
accept_type: 'application/json'
body_format:
formats: ['json']
formats: ['json']
default_format: 'json'
request_format:
formats:
json: 'application/json'
json: 'application/json'
```

Please note that NelmioApiDocBundle has a sandbox limitation where you cannot pass a JSON array as parameter, so you cannot
Expand Down
20 changes: 6 additions & 14 deletions core/operation-path-naming.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,27 @@ Note that `$resourceShortName` contains a camel case string, by default the reso

### Registering the Service

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

```yaml
# app/config/services.yml

services:
app.operation_path_resolver.no_separators:
class: 'AppBundle\\PathResolver\\NoSeparatorsOperationPathResolver'
public: false
```

```xml
<!-- app/config/services.xml -->
# ...

<?xml version="1.0" encoding="UTF-8" ?>
<services>
<service id="app.operation_path_resolver.no_separators" class="AppBundle\PathResolver\NoSeparatorsOperationPathResolver" public="false" />
</services>
'AppBundle\PathResolver\NoSeparatorsOperationPathResolver': ~
```

</configurations>

### Configure It

```yaml
# app/config/config.yml

api_platform:
default_operation_path_resolver: 'app.operation_path_resolver.no_separators'
default_operation_path_resolver: 'AppBundle\PathResolver\NoSeparatorsOperationPathResolver'
```

Previous chapter: [Performance](performance.md)
Expand Down
9 changes: 3 additions & 6 deletions core/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,11 @@ little of configuration:
# app/config/config.yaml

api_platform:

# ...

eager_loading:
max_joins: 100

# ...
```

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)
Expand All @@ -103,12 +102,11 @@ configuration in order to apply it only on join relations having the `EAGER` fet
# app/config/config.yaml

api_platform:

# ...

eager_loading:
force_eager: false

# ...
```

#### Override at resource and operation level
Expand Down Expand Up @@ -212,12 +210,11 @@ If for any reason you don't want the eager loading feature, you can turn it off
# app/config/config.yaml

api_platform:

# ...

eager_loading:
enabled: false

# ...
```

The whole configuration seen before will no longer work and Doctrine will recover its default behavior.
Expand Down
19 changes: 11 additions & 8 deletions core/serialization-groups-and-relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,12 @@ API Platform implements a `ContextBuilder`, which prepares the context for seria
# app/config/services.yml

services:
app.serializer.builder.book:
decorates: api_platform.serializer.context_builder
class: AppBundle\Serializer\BookContextBuilder
arguments: ['@app.serializer.builder.book.inner', '@security.authorization_checker']

# ...

'AppBundle\Serializer\BookContextBuilder':
decorates: 'api_platform.serializer.context_builder'
arguments: [ '@app.serializer.builder.book.inner' ]
```

```php
Expand Down Expand Up @@ -357,16 +359,17 @@ To use this feature, declare a new service with id `app.name_converter`. For exa
# app/config/services.yml

services:
app.name_converter:
class: Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter
public: false

# ...

'Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter': ~
```

```yaml
# app/config/config.yml

api_platform:
name_converter: app.name_converter
name_converter: 'Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter'
```

## Entity Identifier Case
Expand Down
11 changes: 6 additions & 5 deletions core/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ In the following example, we will see how we add extra informations to the outpu
Here is how we add the date on each request in `GET`:

```yaml
# app/config/services.yml
# app/config/services.yml

services:
app.custom.jsonld.normalizer_decorator:
decorates: api_platform.jsonld.normalizer.item
class: AppBundle\Serializer\ApiNormalizer
autowire: true

# ...

'AppBundle\Serializer\ApiNormalizer':
decorates: 'api_platform.jsonld.normalizer.item'
```

```php
Expand Down
24 changes: 15 additions & 9 deletions core/swagger.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
# Swagger Support

## Override Swagger documentation
Symfony allows to [decorate services](https://symfony.com/doc/current/service_container/service_decoration.html), here we need to decorate
`api_platform.swagger.normalizer.documentation`

Symfony allows to [decorate services](https://symfony.com/doc/current/service_container/service_decoration.html), here we
need to decorate `api_platform.swagger.normalizer.documentation`.

### Example
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

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

```yaml
# app/config/services.yml
# app/config/services.yml

services:
app.swagger.swagger_decorator:
decorates: api_platform.swagger.normalizer.documentation
class: 'AppBundle\Swagger\SwaggerDecorator'
arguments: ['@app.swagger.swagger_decorator.inner']

# ...

'AppBundle\Swagger\SwaggerDecorator':
decorates: 'api_platform.swagger.normalizer.documentation'
arguments: [ '@app.swagger.swagger_decorator.inner' ]
```

```php
Expand Down
32 changes: 17 additions & 15 deletions deployment/heroku.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ file:
"pre-install-cmd": [
"Dunglas\\Heroku\\Database::createParameters"
],
// ...
"_": "..."
}
```

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

```yaml
monolog:
# ...
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
monolog:

# ...

nested:
type: stream
path: '%kernel.logs_dir%/%kernel.environment%.log'
level: debug
```

And replace it by:

```yaml
monolog:
# ...
nested:
type: stream
path: "php://stderr"
level: debug
monolog:

# ...

nested:
type: stream
path: 'php://stderr'
level: debug
```

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

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

Can it be easier? Yes it can: we are preparing an API Platform edition preconfigured to run on Heroku! Stay tuned.

Previous chapter: [Introduction](index.md)

Next chapter: [Using API Platform with Docker](docker.md)
1 change: 1 addition & 0 deletions schema-generator/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ rdfa:
types:
Session:
vocabularyNamespace: http://purl.org/net/VideoGameOntology#

# ...
```

Expand Down