-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathHelloCommand.php
More file actions
78 lines (71 loc) · 2.12 KB
/
HelloCommand.php
File metadata and controls
78 lines (71 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace JMose\CommandSchedulerBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class HelloCommand : Say Hello World (can be used for testing purposes
*
* @author Daniel Fischer <dfischer000@gmail.com>
* @package JMose\CommandSchedulerBundle\Command
*/
class HelloCommand extends ContainerAwareCommand
{
/**
* @inheritdoc
*/
protected function configure()
{
$this
->setName('schedulerTest:hello')
->setDescription('Hello world testcommand')
->addOption(
'name',
null,
InputOption::VALUE_OPTIONAL,
'Person who shall be greeted',
'World'
)
->addOption(
'trash',
null,
InputOption::VALUE_OPTIONAL,
'can be set to anything, not used',
false
)
->addOption(
'randReturn',
null,
InputOption::VALUE_OPTIONAL,
'set to enable random return value',
false
)
->addOption(
'randSleep',
null,
InputOption::VALUE_OPTIONAL,
'set to enable random sleep to increase runtime',
false
)
->setHelp('This class is used for testing purposes only');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getOption('name');
$output->writeln('<info>Hello ' . $name . '</info>');
if ($input->getOption('randSleep')) {
sleep(rand(1, 10));
}
$return = 0;
if ($input->getOption('randReturn')) {
$return = rand(0, 5);
}
return $return;
}
}