Skip to content

Commit 526231b

Browse files
author
Degory Valentine
committed
Fixed array argument parsing in ArgvInput.
1 parent f46c6f7 commit 526231b

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Symfony/Component/Console/Input/ArgvInput.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,22 @@ protected function parseLongOption($token)
150150
*/
151151
protected function parseArgument($token)
152152
{
153-
if (!$this->definition->hasArgument(count($this->arguments))) {
154-
throw new \RuntimeException('Too many arguments.');
155-
}
153+
$c = count($this->arguments);
154+
155+
// if input is expecting another argument, add it
156+
if ($this->definition->hasArgument($c)) {
157+
$arg = $this->definition->getArgument($c);
158+
$this->arguments[$arg->getName()] = $arg->isArray()? array($token) : $token;
159+
160+
// if last argument isArray(), append token to last argument
161+
} elseif ($this->definition->hasArgument($c - 1) && $this->definition->getArgument($c - 1)->isArray()) {
162+
$arg = $this->definition->getArgument($c - 1);
163+
$this->arguments[$arg->getName()][] = $token;
156164

157-
$this->arguments[$this->definition->getArgument(count($this->arguments))->getName()] = $token;
165+
// unexpected argument
166+
} else {
167+
throw new RuntimeException('Too many arguments.');
168+
}
158169
}
159170

160171
/**

0 commit comments

Comments
 (0)