Menu

bin/magento and php artisan are one Symfony Console in two costumes
📰

bin/magento and php artisan are one Symfony Console in two costumes

DEV Community: php·Nikita Sirenko·4 days ago
#lPahr5Y2
#devto#dev#command#magento#export
Reading 0:00
15s threshold

I've worked in Magento 2 full-time for 5.5 years, and in Laravel on and off since 2015. Put the two side by side and the names change, but the engineering doesn't. The console is the clearest example.

Same component underneath

In Magento 2, Magento\Framework\Console\Cli , the class behind bin/magento, extends Symfony's Console Application. In Laravel, so does Illuminate\Console\Application , the class behind php artisan. Every command in both frameworks extends Symfony's Command.

So arguments, options, input, output and return codes work the same way. Only registration differs. Magento collects commands from di.xml. Laravel picks up the classes in app/Console/Commands.

The trap they share

When bin/magento starts, it builds every command registered in CommandListInterface , with all of its constructor dependencies, even if all you asked for was cache:flush. On a fresh Magento 2.4.9 install that's 72 command objects per run.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.