@filiberto
To use the Symfony console to execute commands, you need to follow these steps:
1 2 3 |
use SymfonyComponentConsoleApplication; $application = new Application(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
use SymfonyComponentConsoleCommandCommand; use SymfonyComponentConsoleInputInputInterface; use SymfonyComponentConsoleOutputOutputInterface; class MyCommand extends Command { protected function configure() { $this->setName('my:command') ->setDescription('My custom command'); } protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('Hello world!'); } } |
1
|
$application->add(new MyCommand()); |
1
|
$application->run(); |
You can execute the command my:command
by running the following command on your terminal:
1
|
php console my:command |
This will output Hello world!
to the console. You can also get a list of all available commands by running php console list
.