Created
June 8, 2014 21:58
-
-
Save dmouse/3858b461e5e648a6b46f to your computer and use it in GitHub Desktop.
Your own command in Drupal 8 Console see more in http://symfony.com/doc/current/cookbook/console/console_command.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @file | |
| * Contains \Drupal\Acme\Command\AcmeCommand. | |
| */ | |
| namespace Drupal\Acme\Command; | |
| use Symfony\Component\Console\Command\Command; | |
| use Symfony\Component\Console\Input\InputArgument; | |
| use Symfony\Component\Console\Input\InputInterface; | |
| use Symfony\Component\Console\Input\InputOption; | |
| use Symfony\Component\Console\Output\OutputInterface; | |
| class AcmeCommand extends Command | |
| { | |
| protected function configure() | |
| { | |
| $this | |
| ->setName('demo:greet') | |
| ->setDescription('Greet someone') | |
| ->addArgument('name', InputArgument::OPTIONAL, 'Who do you want to greet?') | |
| ->addOption('yell', null, InputOption::VALUE_NONE, 'If set, the task will yell in uppercase letters') | |
| ; | |
| } | |
| protected function execute(InputInterface $input, OutputInterface $output) | |
| { | |
| $name = $input->getArgument('name'); | |
| if ($name) { | |
| $text = 'Hello '.$name; | |
| } else { | |
| $text = 'Hello'; | |
| } | |
| if ($input->getOption('yell')) { | |
| $text = strtoupper($text); | |
| } | |
| $output->writeln($text); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment