Last active
March 9, 2017 09:40
-
-
Save bendavies/cb05d936d1d6cd6bff266aef1ad90bf5 to your computer and use it in GitHub Desktop.
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 | |
<<<CONFIG | |
packages: | |
- "symfony/console: 3.2.4" | |
- "symfony/event-dispatcher: ~3.0" | |
CONFIG; | |
use Symfony\Component\Console\Application; | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\ConsoleEvents; | |
use Symfony\Component\Console\Event\ConsoleCommandEvent; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Component\EventDispatcher\EventDispatcher; | |
class GreetCommand extends Command | |
{ | |
public function configure() | |
{ | |
$this->setName('greet'); | |
} | |
public function execute(InputInterface $input, OutputInterface $output) | |
{ | |
$output->writeln(sprintf("Hello %s!", $input->getArgument('name'))); | |
} | |
} | |
$dispatcher = new EventDispatcher(); | |
$app = new Application(); | |
$app->setDispatcher($dispatcher); | |
$app->add(new GreetCommand()); | |
$dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) { | |
$command = $event->getCommand(); | |
if ($command instanceof GreetCommand) { | |
$command->addArgument('name', InputArgument::REQUIRED, 'Who do you want to greet?'); | |
} | |
}); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment