Skip to content

Commit 2169472

Browse files
author
=
committed
Corrected argument handling
1 parent e6fcb46 commit 2169472

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

Command/DaemonRunCommand.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Symfony\Component\Console\Command\Command;
88
use Symfony\Component\Console\Input\InputArgument;
99
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Input\InputOption;
1011
use Symfony\Component\Console\Output\OutputInterface;
1112
use Symfony\Component\HttpFoundation\Request;
1213
use Symfony\Component\HttpKernel\Kernel;
@@ -27,15 +28,22 @@ protected function configure()
2728
$this
2829
->setName('speedfony:daemon:run')
2930
->setDescription('Execute the FCGI daemon')
30-
->addArgument('socket', InputArgument::OPTIONAL, 'The socket stream to listen on')
31-
->addArgument('port', InputArgument::OPTIONAL, 'Port to listen on')
32-
->addArgument('cycles', InputArgument::OPTIONAL, 'Request cycles to live for, 0 means infinite', 0);
31+
->addArgument('cycles', InputArgument::OPTIONAL, 'Request cycles to live for, 0 means infinite (default is 20)', 20)
32+
->addOption('socket', null, InputOption::VALUE_REQUIRED, 'The socket stream to listen on')
33+
->addOption('port', null, InputOption::VALUE_REQUIRED, 'Port to listen on');
3334
}
3435

3536
protected function execute(InputInterface $input, OutputInterface $output)
3637
{
37-
$getIntegerArgument = function ($argument, $minimumValue) use ($input) {
38-
$value = (string) $input->getArgument($argument);
38+
$getIntegerInput = function ($type, $name, $minimumValue) use ($input) {
39+
if ('argument' === $type) {
40+
$value = (string) $input->getArgument($name);
41+
} elseif ('option' === $type) {
42+
$value = (string) $input->getOption($name);
43+
} else {
44+
throw new \LogicException('Unknown input type: ' . $type);
45+
}
46+
3947
$intValue = (int) $value;
4048

4149
if ((string) $intValue !== $value) {
@@ -47,15 +55,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
4755
return $value;
4856
};
4957

50-
if ($input->hasArgument('socket')) {
51-
$daemon = new StreamSocketDaemon($input->getArgument('socket'));
52-
} elseif ($input->hasArgument('port')) {
53-
$daemon = new SocketDaemon($getIntegerArgument('port', 0));
58+
if (null !== $input->getOption('socket')) {
59+
$daemon = new StreamSocketDaemon($input->getOption('socket'));
60+
} elseif (null !== $input->getOption('port')) {
61+
$daemon = new SocketDaemon($getIntegerInput('option', 'port', 0));
5462
} else {
5563
throw new \Exception('You must specify either the socket or port argument');
5664
}
5765

58-
$maximumCycles = $getIntegerArgument('cycles', 0);
66+
$maximumCycles = $getIntegerInput('argument', 'cycles', 0);
5967

6068
for($cycles = 0; ($maximumCycles == 0) || $cycles < $maximumCycles; $cycles++) {
6169
$request = $daemon->getRequest();

0 commit comments

Comments
 (0)