Chapters
39 Chapters
|
4:45:13
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3, <8.0
Subscribe to download the code!Compatible PHP versions: ^7.1.3, <8.0
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
24.
Context Builder & Service Decoration
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial works great for Symfony 5 and API Platform 2.5/2.6.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.1.3, <8.0",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "^2.1", // v2.4.5
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.13.2
"doctrine/doctrine-bundle": "^1.6", // 1.11.2
"doctrine/doctrine-migrations-bundle": "^2.0", // v2.0.0
"doctrine/orm": "^2.4.5", // v2.7.2
"nelmio/cors-bundle": "^1.5", // 1.5.6
"nesbot/carbon": "^2.17", // 2.21.3
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0", // 4.3.1
"symfony/asset": "4.3.*", // v4.3.2
"symfony/console": "4.3.*", // v4.3.2
"symfony/dotenv": "4.3.*", // v4.3.2
"symfony/expression-language": "4.3.*", // v4.3.2
"symfony/flex": "^1.1", // v1.21.6
"symfony/framework-bundle": "4.3.*", // v4.3.2
"symfony/http-client": "4.3.*", // v4.3.3
"symfony/monolog-bundle": "^3.4", // v3.4.0
"symfony/security-bundle": "4.3.*", // v4.3.2
"symfony/twig-bundle": "4.3.*", // v4.3.2
"symfony/validator": "4.3.*", // v4.3.2
"symfony/webpack-encore-bundle": "^1.6", // v1.6.2
"symfony/yaml": "4.3.*" // v4.3.2
},
"require-dev": {
"hautelook/alice-bundle": "^2.5", // 2.7.3
"symfony/browser-kit": "4.3.*", // v4.3.3
"symfony/css-selector": "4.3.*", // v4.3.3
"symfony/maker-bundle": "^1.11", // v1.12.0
"symfony/phpunit-bridge": "^4.3", // v4.3.3
"symfony/stopwatch": "4.3.*", // v4.3.2
"symfony/web-profiler-bundle": "4.3.*" // v4.3.2
}
}
11 Comments
Hi, what is the reason we use `autoconfigure: false` in the service configuration? I mean, I do understand in general what it means, but why here? Thank you!
Hey Denis V.!
Excellent question. So... basically the docs are wrong here and it's not needed. I "caught" this when I built the code for the tutorial (which is why you don't see it included on the code block on this page) but forgot to mention & remove it in the video. Basically, API Platform does not register any auto-configuration rules for
SerializerContextBuilderInterface... and so the autoconfigure: false is meaningless. Iirc, I asked @dunglas about this to verify and he agreed.Cheers!
It took me a day to find out that for GraphQL we need to use
api_platform.graphql.serializer.context_builderinstead ofapi_platform.serializer.context_builderHey Mostafa Shahverdy
Sorry for the late reply and for the confusion. ApiPlatform comes with different implementations for working with GraphQL as you already discovered. We'll add a note about it to the tutorial. Thanks for sharing it :)
Cheers!
I haved changed to api_platform.graphql.serializer.context_builder but the query have error on phoneNumber when it set dynamically for admin. Do you have the same problem when using GraphQL and your solution? Thanks
Hi
I have been trying to implement the "LoggerAwareInterface" with ContextBuilder and getting an error "Error: Call to a member function debug() on null". It seems for some reason LoggerAwareInterface not working with decorators (I am not quiet sure though).
<br /><?php<br />final class AdminGroupsContextBuilder implements SerializerContextBuilderInterface, LoggerAwareInterface<br />{}<br />Hey Mohamed
I believe it should work when decorating a service but I'm not 100% sure. Can you give it a try with another service? Also, could yo show me your code?
Cheers!
Hi
Thanks for the quick response. Here is the gist....
https://gist.github.com/zsp...
UserDenormalizer.php works fine!
SuperAdminGroupContextBuilder.php not working and throwing the following error...
"Call to a member function debug() on null"
(ofcourse there are other work arounds but I just want to make sure it's not a bug)
Thank you
Hey Mohamed
The problem is that you disabled the autoconfiguration on your service. Is there any particular reason?
If you really need to disable it, then what you can do is to use Dependency Injection instead of relying on the interface magic. You can find some more info here: https://symfony.com/doc/cur...
Cheers!
Hi
Excellent!!! no particular reason except for I followed the exact same steps provided by the api platform documentation and this video tutorial. (https://api-platform.com/do... and video timeline ~03:00). Yes, I am already using dependency injection and it works fine.
So now I am not quite sure why the document example disables it. I will find out!
Thank you very much for your quick response and support. Very helpful!
Cheers!
Ohh, that's interesting. I don't know either why they disable it. Probably a mistake? If you find out the reason, pleas let us know!
Cheers!
"Houston: no signs of life"
Start the conversation!