If a command with the same name already exists, it will be overridden.
If the command is not enabled it will not be added.
use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class MyCommand extends Command { protected function configure() { $this->setName('my_command') ->setDescription('This is my command'); // add any other configuration options here } protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('Hello World!'); } } $application = new Application(); // Add the "MyCommand" command to the application $application->add(new MyCommand()); // Run the application $application->run();In this example, we define a new command called `MyCommand` by extending the `Command` class. We configure the command by setting its name and description in the `configure()` method, and implement the command's logic in the `execute()` method. We then create a new instance of the `Application` class and add the `MyCommand` command to it using the `add()` method. Finally, we run the application using the `run()` method. Overall, Symfony\Component\Console is a robust and flexible library that can help you build powerful console-based applications in PHP.