diff options
Diffstat (limited to 'src/Acme/DemoBundle/Command/HelloWorldCommand.php')
-rw-r--r-- | src/Acme/DemoBundle/Command/HelloWorldCommand.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/Acme/DemoBundle/Command/HelloWorldCommand.php b/src/Acme/DemoBundle/Command/HelloWorldCommand.php new file mode 100644 index 00000000..998cbcdf --- /dev/null +++ b/src/Acme/DemoBundle/Command/HelloWorldCommand.php | |||
@@ -0,0 +1,48 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Acme\DemoBundle\Command; | ||
4 | |||
5 | use Symfony\Component\Console\Command\Command; | ||
6 | use Symfony\Component\Console\Input\InputArgument; | ||
7 | use Symfony\Component\Console\Input\InputInterface; | ||
8 | use Symfony\Component\Console\Output\OutputInterface; | ||
9 | |||
10 | /** | ||
11 | * Hello World command for demo purposes. | ||
12 | * | ||
13 | * You could also extend from Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand | ||
14 | * to get access to the container via $this->getContainer(). | ||
15 | * | ||
16 | * @author Tobias Schultze <http://tobion.de> | ||
17 | */ | ||
18 | class HelloWorldCommand extends Command | ||
19 | { | ||
20 | /** | ||
21 | * {@inheritdoc} | ||
22 | */ | ||
23 | protected function configure() | ||
24 | { | ||
25 | $this | ||
26 | ->setName('acme:hello') | ||
27 | ->setDescription('Hello World example command') | ||
28 | ->addArgument('who', InputArgument::OPTIONAL, 'Who to greet.', 'World') | ||
29 | ->setHelp(<<<EOF | ||
30 | The <info>%command.name%</info> command greets somebody or everybody: | ||
31 | |||
32 | <info>php %command.full_name%</info> | ||
33 | |||
34 | The optional argument specifies who to greet: | ||
35 | |||
36 | <info>php %command.full_name%</info> Fabien | ||
37 | EOF | ||
38 | ); | ||
39 | } | ||
40 | |||
41 | /** | ||
42 | * {@inheritdoc} | ||
43 | */ | ||
44 | protected function execute(InputInterface $input, OutputInterface $output) | ||
45 | { | ||
46 | $output->writeln(sprintf('Hello <comment>%s</comment>!', $input->getArgument('who'))); | ||
47 | } | ||
48 | } | ||