19.
Fun with Commands
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.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
11 Comments
Thnk you !
So far good course.
I hope that next course/tutorial will cover audit log, action logs, form dropdown dependency, producing pdfs from templates if possible, testing of controllers and whole site (shifting logic from controllers to services??) updating/overwriting of build-in templates, creating global variables for templates, authorization, role hierarchy etc.
Cant wait for the next video.
Can I find somewhere what is on your todo list with some dates?
Hey Peter,
Thanks for your suggestions, most of them we're going to cover in the upcoming Symfony 4 screencasts, but probably not all of them, at least in the nearest future.
Yes, you can check out upcoming screencasts on this page: https://knpuniversity.com/c... but unfortunately we do not have any dates, but we're trying to stick the order of those upcoming screencasts.
Cheers!
Thank you ! Small question : For a long time command, is it recommended to set `set_time_limit(0);` ?
Hey Ahmedbhs,
It might be a good idea, and most probably you already have such config for the php-cli. Not a good idea to do this for php-fpm config, but it might depend on your specific user case.
Though, I'd not recommend you to run your long-time commands too long if we're talking about PHP, because PHP is far from perfect for this, it has a lot of memory leaks, etc. And also performance on long-time commands will be reduced most probably too. Usually, PHP devs make commands that are safe to be run more than once, i.e. the business logic in it will skip already handled cases and continue from the place where it stopped.
I hope this helps!
Cheers!
The command works when it is in src/command but it seems to not autowire when i put the command in a vendor package like vendor/name/package/src/Command/MyCommand any idea ?
Yo Frogg!
You're 100% correct! The
src/directory is special because of some code in the beginning of yourconfig/services.yamlfile:Those lines of code are responsible for (A) auto-registering everything in src/ as a service (that's what the second section does) and activating autowiring (and autoconfiguration) for all services registered in this file (that's the first part). That's why, if you put something anywhere outside of src/, this won't work. As a best-practice, if you're building a reusable bundle, you should wire your services manually. Here are some details about that https://symfonycasts.com/screencast/symfony-bundle/bundle-services
I hope that helps! Excellent question!
Cheers!
Thanks for your answer, it works now.
I created a Bundle as you said in your other post:
src/Bundle.php<br />src/Resources/config/services.xml<br />src/DependencyInjection/Extension.php<br />src/Command/Command.php<br />but it didn't add automatically my bundle in the symfony config/bundle.php
So i checked how FOS bundles did, and i figured out there is a configuration missing to achieve it:
in the bundle composer.json i added:
`{
}`
And now the command works when the bundle is installed !
Thanks a lot.
Hello team,
in the "->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'text')" can you please explain the second argument "null" is short hand of the first argument "format" and that one can write short hand "f" such as "->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'The output format', 'text')"
I had to read original doc https://symfony.com/doc/cur... to understand. Thank you for all your works!
Hey Dung L.!
Sorry for my slow reply! Thanks for posting the tip here :). I don't often use that 2nd argument (the "shortcut"), but it's a really nice one to know.
Cheers!
Yep, for learning. Thanks!
"Houston: no signs of life"
Start the conversation!