-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add documentation about SerializerAwareDataProviderInterface #336
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
Conversation
core/data-providers.md
Outdated
## Inject Serializer in a ItemDataProvider | ||
|
||
In some case, you may need to inject the Serializer in your DataProvider. For CollectionDataProvider, you can inject it | ||
easily without risk, but for ItemDataProvider you will experience a CircularReferenceException. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some cases, you may need to inject the Serializer in your DataProvider. There are no issues with the CollectionDataProvider, but when injecting it in the ItemDataProvider it will throw a CircularReferenceException.
core/data-providers.md
Outdated
In some case, you may need to inject the Serializer in your DataProvider. For CollectionDataProvider, you can inject it | ||
easily without risk, but for ItemDataProvider you will experience a CircularReferenceException. | ||
|
||
That's why we implemented the SerializerAwareDataProviderInterface to help you inject the Serializer dependency: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this reason, we implemented the SerializerAwareDataProviderInterface:
core/data-providers.md
Outdated
// Deserialize data using Serializer | ||
return $this->getSerializer()->deserialize($data, BlogPost::class, 'custom'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this stuff. Nice improvement!
core/data-providers.md
Outdated
@@ -125,6 +125,46 @@ services: | |||
tags: [ 'api_platform.item_data_provider' ] | |||
``` | |||
|
|||
## Inject Serializer in a ItemDataProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Injecting the Serializer in an `ItemDataProvider`
core/data-providers.md
Outdated
@@ -125,6 +125,46 @@ services: | |||
tags: [ 'api_platform.item_data_provider' ] | |||
``` | |||
|
|||
## Inject Serializer in a ItemDataProvider | |||
|
|||
In some cases, you may need to inject the Serializer in your DataProvider. There are no issues with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add backticks aroung class and exception names (everywhere)?
core/data-providers.md
Outdated
|
||
```php | ||
<?php | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line to remove
core/data-providers.md
Outdated
// Retrieve data from anywhere you want, in a custom format | ||
$data = '...'; | ||
|
||
// Deserialize data using Serializer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the Serializer
Can you also update the TOC please? |
Thanks @vincentchalamon! |
Related to api-platform/core#1184