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!
28.
Dynamic Groups without Caching
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
}
}
6 Comments
Hi!!! I'm trying to find out how to pluralize the words to our native language, Portuguese. It seems to be related to the class in doctrine/inflector/lib/Doctrine/Inflector/InflectorFactory.php. But it is hardcoded there:
`public static function create() : LanguageInflectorFactory
If I change that to self::createForLanguage(Language::PORTUGUESE) it works. I think that it should be configurable.
Thanks
Hey Carlos,
Yes, I think you need to call that "createForLanguage()" method directly and pass the language you want. That method is also public, so you can call it on that object. The "create()" method is really hardcoded to the English version.
Cheers!
Hey Victor, thank you! But where could I call this method? Because in anywhere I'm calling the create() method. It's part of the configuration. I couldn't find in the Api Platform docs where to change this. I searched too in the Doctrine and Symfony docs, but actually, in the Symfony docs it says that now the Inflector Component is deprecated (https://symfony.com/doc/cur.... Maybe there's a way to configure through yaml, or maybe through decoration?
Hey Carlos!
Happy new year!
Yea, I see the issue. First, it's not the Symfony inflector we're dealing with - but the Doctrine one... not that this helps us really (just noting that for clarity). Inside API Platform, I don't see any hook points: they call the Inflector statically in a few places.
But, don't despair! Even though we can't override/configure this InflectorFactory directly, we CAN configure/control the things that use it. And actually, I only the pluralize method used in 2 places:
A)
RouteNameGeneratorB)
DashPathSegmentNameGeneratorandUnderscorePathSegmentNameGenerator(the 2nd is the default, iirc)My guess is that what you want is to control how the URLs are generated (e.g. Product class -> /api/products) is that correct? If so, then you want to override the "path name segment generator". We talk about that (kinda) here: https://symfonycasts.com/screencast/api-platform-extending/custom-resource#codeblock-0afd22e71b
What I would do is:
Create a class that implements
PathSegmentNameGeneratorInterfaceand decorates theapi_platform.path_segment_name_generator.dashservice. Then, configure YOUR new service under theapi_platform. path_segment_name_generatorconfig.Let me know if that helps!
Cheers!
Hey Ryan, thanks again. Actually the only problem is if I choose to go with the plurals in the resources. I think that I will set the "path" inside each Entity and stick with the singular words. Can you tell me your opinion, would I lose something doing that?
Hey Carlos!
I don't see any issue with being explicit and putting the "path" inside each entity - just more work for you (and, of course, you should be careful to be consistent of course!) but always a solid thing to do :).
Cheers!
"Houston: no signs of life"
Start the conversation!