Chapters
37 Chapters
|
3:43:31
|
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.1.2
"doctrine/annotations": "^2.0", // 2.0.1
"doctrine/doctrine-bundle": "^2.8", // 2.8.3
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.2.2
"doctrine/orm": "^2.14", // 2.14.1
"nelmio/cors-bundle": "^2.2", // 2.2.0
"nesbot/carbon": "^2.64", // 2.66.0
"phpdocumentor/reflection-docblock": "^5.3", // 5.3.0
"phpstan/phpdoc-parser": "^1.15", // 1.16.1
"symfony/asset": "6.2.*", // v6.2.5
"symfony/console": "6.2.*", // v6.2.5
"symfony/dotenv": "6.2.*", // v6.2.5
"symfony/expression-language": "6.2.*", // v6.2.5
"symfony/flex": "^2", // v2.2.4
"symfony/framework-bundle": "6.2.*", // v6.2.5
"symfony/property-access": "6.2.*", // v6.2.5
"symfony/property-info": "6.2.*", // v6.2.5
"symfony/runtime": "6.2.*", // v6.2.5
"symfony/security-bundle": "6.2.*", // v6.2.6
"symfony/serializer": "6.2.*", // v6.2.5
"symfony/twig-bundle": "6.2.*", // v6.2.5
"symfony/ux-react": "^2.6", // v2.7.1
"symfony/ux-vue": "^2.7", // v2.7.1
"symfony/validator": "6.2.*", // v6.2.5
"symfony/webpack-encore-bundle": "^1.16", // v1.16.1
"symfony/yaml": "6.2.*" // v6.2.5
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.2
"mtdowling/jmespath.php": "^2.6", // 2.6.1
"phpunit/phpunit": "^9.5", // 9.6.3
"symfony/browser-kit": "6.2.*", // v6.2.5
"symfony/css-selector": "6.2.*", // v6.2.5
"symfony/debug-bundle": "6.2.*", // v6.2.5
"symfony/maker-bundle": "^1.48", // v1.48.0
"symfony/monolog-bundle": "^3.0", // v3.8.0
"symfony/phpunit-bridge": "^6.2", // v6.2.5
"symfony/stopwatch": "6.2.*", // v6.2.5
"symfony/web-profiler-bundle": "6.2.*", // v6.2.5
"zenstruck/browser": "^1.2", // v1.2.0
"zenstruck/foundry": "^1.26" // v1.28.0
}
}
22 Comments
This is a minor point but might help someone out. On MacOS Docker v4.0 and later, the
docker-composecommand is now integrated into the CLI. So instead of runningdocker-compose up -dyou rundocker composer up -d. Not sure if the same change was made on Windows. Maybe someone can add that note to the README.md file. Thx!Hey @CDesign ,
Thanks for this tip! Yeah, we even have a note somewhere in the course about it :)
Cheers!
Hello,
I've got a problem here. I downloaded a source code, installed composer and npm, but after symfony serve I've got that kind of error:
Attempted to load class "Locale" from the global namespace.<br />Did you forget a "use" statement for "Symfony\Component\Validator\Constraints\Locale"?The solution is to install intl extension and to enable it in your php.ini :) Hope it will help anyone who will issues the same issue in the future, thanks
Hey sukhoy,
Yes, you're right, that error confuses more than it helps. Thanks for sharing your solution!
About environment varibale to disable docs (at 7:56).
As far as i know it is not possible for now, as
api_platformconfig loaded during a compile time. So it is has not picked up ENV variables, and next configuration does not work:My current sollution, is:
So if you know the solution how to do that with Environment varibales. Please share.
Hey @Oleh-K!
Ah, you're right! I was assuming too much! The APIPlatform Symfony integration references those variables at compile time (like you said). That would need to be fixed inside API Platform, but actually, I think it's not reasonably fixable. By setting, for example,
enable_swaggertofalse, a set of services is removed from the container (which is good - no reason to have those extra service around if they're not used). It would be a decent bit of work to allow this config to use environment variables, and the end result is that people who do want to disable them would still have these extra services "available" in the container, even though they're not used. Not a huge deal, but also probably a good reason not to "fix it".Anyway, I appreciate you pointing this out! I'll add a note to the course.
Cheers!
Anyway, thank you very much! I've found many helpful things in your course.
Is there a way to show an endpoint only to a specific role?
Hey @ToNy
Yes, you can check for the user's role inside your controller's method, or you can use the
#[IsGranted()]attribute. Reference to the docs: https://symfony.com/doc/current/security.html#security-securing-controller-attributesCheers!
Thanks for your reply! I'm affraid that Iphrased my question poorly, so I'll start again. I'm protecting the /api route using access_control in security.yaml, so only authenticated users can access the docs. I want to know if, instead of showing all the endpoints in the docs (swagger or redoc), show only the ones that the user has access to, based on the user roles and the security of the entity declared in the ApiResource annotation.
Hey @ToNy!
I think I understand and it seems reasonable. But it can be tricky to pull off. We talk about something kind of similar in an API Platform 2 tutorial - https://symfonycasts.com/screencast/api-platform2-security/resource-metadata-factory
There, we are trying to add some extra serialization groups in a way that our API docs will notice. You may be able to extend this to dynamically add groups based on the currently-authenticated user.
Another option might be to decorate and customize the
OpenApiFactory- perhaps removing resources based on the current user- https://symfonycasts.com/screencast/api-platform-security/open-api-decorationLet me know if any of these are successful.
Cheers!
Apart from the fact that I need to undo the changes made at the end. Did you notice that the frontend doesn't work with the documentation disabled?
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "api_entrypoint" as such route does not exist.").
Hey @Jamezs!
I believe you're referring to the homepage of the app, right? If so, yea, that's expected - but that's just due to how I built the app :). That custom homepage I built references the
api_entrypointroute so that it can link to the API homepage. So in a real app, if you disabled the docs, as long as you didn't try to link to this route, you'd be good ;).Cheers!
Hello!
I have a question about how you did the initial login, since it appears created directly in the video, are you creating it through make:controller login? If not, could I create it this way?
Hey @Fran!
At the start of this tutorial, the frontend and login stuff is pretty simple. It's a
MainController::homepage()that rendersmain/homepage.html.twig(and that controller is dead-simple). The template itself is pretty much empty except that it renders a Vue app, which renders the login form. All of that was created by hand. The controller and template and very simple and small (you could definitely usemake:controllerto get this), but I created the Vue app by hand.In a normal Symfony app, I would probably build my login form directly in PHP & Twig. For that, I'd use
make:authand choose the "login form" option. That will generate you the controller & template for the login form + a few other things.Does that help? Let me know!
Cheers!
Short question, the editor in use is Phpstrorm? Is this a special skin?
Hey @Klaus-M
Yes, it is PhpStorm, and I believe Ryan uses the "Atom Material Icons" plugin to enhance his editor's theme
Cheers!
Yes, that's it. Thank you very much.
Cheers!
I also ask the same question here, part 2 ok and what would part 1 be ? Thank you
Hey @pasquale_pellicani ,
I'm not sure I understand the question :)
What who else is asking here and what exactly? I see only your comment on this page :)
But in case you're looking for part 1, here it is: https://symfonycasts.com/screencast/api-platform .
Cheers!
Thank you very much, it would be ideal to change the title of the courses with part 1 and part 2 because I had difficulty understanding the order of the two courses. I take the opportunity to thank you for the excellent work done ;)
Hey @pasquale_pellicani ,
I see, yeah, it might not be clear enough. I'd try to add cross-link to this course. Also, you can always can look at the track to find the related courses and the correct order: https://symfonycasts.com/tracks/rest#api-platform-3
I hope this helps!
Cheers!
"Houston: no signs of life"
Start the conversation!