Chapters
28 Chapters
|
2:51:42
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
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!
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!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "^3.0", // v3.0.8
"doctrine/annotations": "^1.0", // 1.14.2
"doctrine/doctrine-bundle": "^2.8", // 2.8.0
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.2.2
"doctrine/orm": "^2.14", // 2.14.0
"nelmio/cors-bundle": "^2.2", // 2.2.0
"nesbot/carbon": "^2.64", // 2.64.1
"phpdocumentor/reflection-docblock": "^5.3", // 5.3.0
"phpstan/phpdoc-parser": "^1.15", // 1.15.3
"symfony/asset": "6.2.*", // v6.2.0
"symfony/console": "6.2.*", // v6.2.3
"symfony/dotenv": "6.2.*", // v6.2.0
"symfony/expression-language": "6.2.*", // v6.2.2
"symfony/flex": "^2", // v2.2.4
"symfony/framework-bundle": "6.2.*", // v6.2.3
"symfony/property-access": "6.2.*", // v6.2.3
"symfony/property-info": "6.2.*", // v6.2.3
"symfony/runtime": "6.2.*", // v6.2.0
"symfony/security-bundle": "6.2.*", // v6.2.3
"symfony/serializer": "6.2.*", // v6.2.3
"symfony/twig-bundle": "6.2.*", // v6.2.3
"symfony/ux-react": "^2.6", // v2.6.1
"symfony/validator": "6.2.*", // v6.2.3
"symfony/webpack-encore-bundle": "^1.16", // v1.16.0
"symfony/yaml": "6.2.*" // v6.2.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.2
"symfony/debug-bundle": "6.2.*", // v6.2.1
"symfony/maker-bundle": "^1.48", // v1.48.0
"symfony/monolog-bundle": "^3.0", // v3.8.0
"symfony/stopwatch": "6.2.*", // v6.2.0
"symfony/web-profiler-bundle": "6.2.*", // v6.2.4
"zenstruck/foundry": "^1.26" // v1.26.0
}
}
13 Comments
Following this fab course on symfony 8, php8.5 and API platform 4.3. So far so good with very few minor changes.
It may be due to the newer versions above, but my api docs only recognise altered getter/setter methods with bin/console cache:clear and often rm -rf var/cache/dev in addition.
Have aliased them in my shell script, would recommend the same to others struggling to see the api changes immediately.
Hey @greg-b
Thanks for the kind words, glad the course is treating you well :)
Quick clarification: you're right it's a newer-versions thing, but it landed in API Platform 3.0. In API Platform 2, dev used to rebuilt resource/property metadata (the info read from your getters/setters and phpdoc) on every request via an in-memory array cache, so changes showed instantly. Since 3.0 that metadata lives in the persistent cache.system pool even in dev, and it can't reload just the one resource you touched — it's all-or-nothing — so it won't auto-invalidate on a getter change. Your alias is a perfectly good pragmatic fix.
If you'd rather get the instant-update behavior back, point API Platform's metadata pools at the array adapter in dev only:
you may want to double-check the pool in case I got one wrong
Cheers!
Since I am upgrading an app from 2.6 to 3 right now, I was wondering about a behavior of the serializer that I ovserved.
In API-Platform >= 3, the default setting in the api_platform.yaml is:
So far, so good. Properties, which are null, are no longer part of the response.
But in that specific app I work a lot with Doctrine Embeddables because I have giant forms, and it is a great way to put fields into logical blocks.
But when all properties of an embeddable are null, the endpoint returns an empty array.
I expected the embeddable not to be returned at all, or to be an empty object, but an empty array is returned.
Is that really the desired behavior?
I am right now wondering how to deal with that, since I have dozens of embeddable in use in that app.
I could modify all the getters and manually loop though all the properties and return null, if they are all null, or create some kind of custom normalizer.
Furthermore, I have two questions:
Is that really the wanted behavior?
What is the best workaround?
Hey @TristanoMilano!
Ooooh, upgrading! :)
I... think so? So if you're fetching
/api/invoice/5and it has an embeddableaddressproperty... and every field in thatAddressobject is null, then it does make sense to me that the response WOULD contain anaddressproperty (sinceInvoice.addressdoes contain anAddressobject)... but then each property inside that "array" would be missing, since each property is null. But, this is just my opinion: it makes sense to me, but this is the first time I've thought about it!I don't know if this helps you, but you are free to change
skip_null_valuestofalse. They changed it totruebecause that better fits the JSON-LD spec, iirc. So, feel free to change this to false. Though, thenaddresswould still be an array/object... withnullproperties. So I'm not sure if that is better for your or not :p.Otherwise, the only solution I can think of is some sort of custom normalizer. That normalize, I think, could "support" the
Addressobject (or any other embeddable), check to see if every property isnull, and if it is, returnnull. Else, call the core normalizer system so it can do its normal work. That... doesn't seem unreasonable to me, but custom normalizers can get complex.Let me know what you end up doing and how it goes!
Cheers!
When I'm trying to execute PUT method I get following error:
Also my getters where generated with return type
staticnotselflike on video, Did I do something wrong?@Damian same problem for me
It seems that it is due to the new behavior of the PUT method which is now conform to the RFC 9110.
It does create or replace (all the data of ressource) with the new ones. The partial replace have now to be done with the PATCH method.
You can change this behavior in the config file (api_platform.yaml) : change the
standard_puttofalseYup! We will talk about this later in the tutorial. But if you're starting with a new project, a recent recipe change included the
standard_put: trueinconfig/packages/api_platform.yaml, which is why you see different behavior than I have in the tutorial up to this point.I'll add a note to help people with this.
Thanks!
Heya, for some reason visual studio code marks "Carbon" as an error in the getPlunderedAtAgo() method that its used here.
Hey @TronZin
That's unexpected. Could you double-check if that method still exists in the Carbon library? You might have got a newer version and they renamed the method. If that's not the case, your IDE may not have indexed the library correctly
Hi,
when I installed nesbot/carbon then browser shows an error:
Attempted to load class "Locale" from the global namespace.<br />Did you forget a "use" statement for "Symfony\Component\Validator\Constraints\Locale"?Adding use statment does not helps :( any ideas?
Hey Szymon,
I believe you haven't installed the
php-intlmodule in your local environment. If you're on Ubuntu, you can do thissudo apt-get install php-intlCheers!
I had installed intl extension but it required to uncomment lines in several places in php/php.ini (I have Windows 10)
I see... well, as far as I know Windows is not very friendly for developing purposes. That's why I use Windows WSL, it's not perfect but it gets the job done :)
"Houston: no signs of life"
Start the conversation!