Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilmoore/767014 to your computer and use it in GitHub Desktop.
Save wilmoore/767014 to your computer and use it in GitHub Desktop.
Symfony Console -- injecting additional top-level options/arguments at the program level
/**
* php job-queue.php --environment=local [command|namespace:command]
* php job-queue.php --environment=local job:monitor
*
* NOTE:
* looks like you can actually put the option anywhere...the folllowing works just fine
* > php job-queue.php job:monitor --environment=local
*/
// inject custom required argument (execution halts if program is called without this argument)
$this->definition->addArguments(array(
new InputArgument('environment', InputArgument::REQUIRED, 'application environment'),
));
// inject custom required option (option actually seems to be optional even though it is defined as required)
// From a command, you can now do:
// $input->getOption('environment')
$this->definition->addOptions(array(
new InputOption('--environment', '-e', InputOption::VALUE_REQUIRED, 'application environment'),
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment