How To Create CLI App & Commands - Full PHP 8 Tutorial

How To Create CLI App & Commands - Full PHP 8 Tutorial

Program With Gio

1 год назад

10,651 Просмотров

In this video we build a command line interface to be able to run doctrine ORM, DBAL & migration commands as well as the custom commands that we'll create. We are also introduced to Symfony Console component & how to use it to build CLI tools.

SOME OF THE WAYS YOU CAN SUPPORT THE CHANNEL
👍 Smash the like button
🤝 Subscribe to the channel & turn the notifications on
💬 Post comments, any feedback is greatly appreciated
⭐ Become a Patreon: https://www.patreon.com/programwithgio
THANK YOU!

🛠️ TOOLS & SERVICES I USE
Cloudways Hosting - https://platform.cloudways.com/signup?id=1175002&data1=bw&coupon=GIO15
Digital Ocean Hosting - Get 200$ credit - https://m.do.co/c/38b935ad74e5
Domains on Namecheap - https://namecheap.pxf.io/rnRjdQ
Envato Elements - https://1.envato.market/c/2937311/298927/4662

LESSON 3.31
Course Outline - https://github.com/ggelashvili/learnphptherightway-outline
Course Playlist - https://www.youtube.com/playlist?list=PLr3d3QYzkw2xabQRUpcZ_IBk9W50M9pe-

RESOURCES
Source Repo - https://github.com/ggelashvili/learnphptherightway-project/tree/3.31
Symfony Console - https://symfony.com/doc/current/components/console.html

Table of Contents
00:00 - Intro
00:31 - Create Doctrine CLI
04:58 - Cloudways Promo
05:42 - Add Migration Commands
09:36 - Symfony Console Component
12:55 - Create Commands
15:11 - Refactor Commands to Configs
21:03 - Outro

** Affiliate Disclaimer: Some of the above links may be affiliate links, which may generate me a sales commission at no additional cost to you.

Тэги:

#php8_tutorial #php_course #learn_php_the_right_way #object_oriented_php #full_php_course #php_in_2021 #advanced_php_course #php_8.1 #symfony_console #build_cli_tool_with_symfony_console #php_command_line_interface #php_cli #create_commands_in_php #cli_commands
Ссылки и html тэги не поддерживаются


Комментарии:

@bakytzhan674
@bakytzhan674 - 26.11.2023 10:15

Is it also possible to add phpunit commands to our myapp command?

Ответить
@bakytzhan674
@bakytzhan674 - 26.11.2023 09:22

Thanks for the tutorial. Do you perhaps know why I do not get any errors in my console if 'myapp.php' has errors? When I execute it, if there is any error, it does not return anything. But, if the code is correct, the script executes properly.

Ответить
@TomiBorchert
@TomiBorchert - 08.06.2023 16:27

What do you think of the slim bridge component? ever tried it?

Ответить
@chrisodillman3355
@chrisodillman3355 - 13.05.2023 11:49

I am working in symfony projects for a few months now and only had a bit experience with laravel before that. It was a bit tough in the begining but a few weeks ago it really started kickin in and i love working with symfony so much! Every time i watch you explain something i learn so much cool stuff. Thanks a lot. I wrote a few commands this week and looking forward to watch you do it 😀

Ответить
@hansschuijff
@hansschuijff - 06.11.2022 18:47

Great lesson to end this section with, Gio. Fast and much, but with pausing and going back, I could follow it and find you build the complexity up well. It's quite a journey, this course you offer and it brought me to solutions I might otherwise not even have considered in any near future.

One question popped up in me... you noticed in the lesson that ConsoleRunner exists in Migration, ORM and DBAL and decided to just copy. That's alright of course, but I wondered if it would have also been possible to just use an alias and let Doctrine do the work on adding the commands too. They have different namespaces.

So I tried changing

$application->addCommands($migrationCommands($dependencyFactory));

to:

use Doctrine\Migrations\Tools\Console\ConsoleRunner as MigrationConsoleRunner;
MigrationConsoleRunner::addCommands( $application, $dependencyFactory );

And the commands still seem to work.

Perhaps you choose the other path as a demo, or you didn't want the entire class loaded for one method. But it was fun to also try this. It seemed a more quick and easy way to get all the commands of Migration.


Up to the next series. 🙂Thanks so much.

Ответить
@johncarlosarmiento2666
@johncarlosarmiento2666 - 27.09.2022 04:32

Thank you keep up the course!

Ответить
@jamesondanda1724
@jamesondanda1724 - 16.09.2022 14:24

Thanks GIO for the insights.

Ответить
@memack101
@memack101 - 14.09.2022 03:06

Thank you.

Ответить
@Zubbee
@Zubbee - 12.09.2022 23:26

Ok Gio. I'm done. Custom commands ✅, dbal, orm and migration commands on myapp cli ✅. Refactoring ✅. I took a while though cause I was trying to work out ways to work faster with docker. Was a long detour but I learnt a lot. Turns out that ultimately I'll have to upgrade to a system with a higher spec. But for now I'm stable and ready for the next lesson. Thanks a lot Gio.

Ответить
@tarsierontherun
@tarsierontherun - 06.09.2022 20:52

Really great stuff my man!

Ответить
@Zubbee
@Zubbee - 06.09.2022 16:56

Hi Gio, Just watched, this is another level! I always thought cli stuff was deep programming and beyond me but here you are showing us a thing or two. I'm exited! I haven't refactored mine yet though, just watched and will certainly do. but I have a question. Why is it best for us to build a custom cli and not use the doctrine cli? Just trying to understand the importance and how it impacts on the quality of work done by a programmer. Thanks a lot Gio, you are the best I know...

Ответить
@Zubbee
@Zubbee - 06.09.2022 16:25

Great. Been anticipating. Let me delve in. Thanks Gio

Ответить
@FGj-xj7rd
@FGj-xj7rd - 06.09.2022 15:52

Nah, I write raw scripts at my work. For DB migrations. 😎💪

Ответить