use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class HelloWorldCommand extends Command { protected function configure() { $this ->setName('hello:world') ->setDescription('Prints "Hello World!" to the console'); } protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('Hello World!'); } }
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class GreetCommand extends Command { protected function configure() { $this ->setName('greet') ->setDescription('Greet someone') ->addArgument('name', InputArgument::REQUIRED, 'Who do you want to greet?'); } protected function execute(InputInterface $input, OutputInterface $output) { $name = $input->getArgument('name'); $output->writeln('Hello, '.$name); } }This code creates a command called `greet` that takes a required argument `name` and outputs a personalized greeting to the console. Overall, the Command component in the Symfony Console package library is useful for creating custom command-line applications in PHP.