use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; class MyCommand extends Command { public function configure() { $this ->setName('mycommand') ->setDescription('My command') ->addArgument('foo', InputArgument::REQUIRED, 'The foo argument') ->addArgument('bar', InputArgument::OPTIONAL, 'The bar argument') ; } public function execute(InputInterface $input, OutputInterface $output) { $foo = $input->getArgument('foo'); $bar = $input->getArgument('bar'); // ... } } $input = new ArgvInput(); $command = new MyCommand(); $command->run($input, new ConsoleOutput());
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; class MyCommand extends Command { public function configure() { $this ->setName('mycommand') ->setDescription('My command') ->addOption('verbose', 'v', InputOption::VALUE_NONE, 'Increase verbosity') ; } public function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('verbose')) { $output->writeln('Verbose mode enabled'); } // ... } } $input = new ArgvInput(); $command = new MyCommand(); $command->run($input, new ConsoleOutput());This example defines a command called "mycommand" with an option called "verbose" (-v). The execute method checks whether this option was specified using the InputInterface's getOption method and prints a message if it was. Overall, the Symfony\Component\Console\Input\InputInterface package and its bind method are useful for handling command line arguments and options in PHP CLI applications.