Selaa lähdekoodia

Fixed array argument parsing in ArgvInput.

Degory Valentine 14 vuotta sitten
vanhempi
commit
0306c9aa66
1 muutettua tiedostoa jossa 15 lisäystä ja 4 poistoa
  1. 15 4
      src/Symfony/Component/Console/Input/ArgvInput.php

+ 15 - 4
src/Symfony/Component/Console/Input/ArgvInput.php

@@ -150,11 +150,22 @@ class ArgvInput extends Input
      */
     protected function parseArgument($token)
     {
-        if (!$this->definition->hasArgument(count($this->arguments))) {
-            throw new \RuntimeException('Too many arguments.');
-        }
+        $c = count($this->arguments);
+
+        // if input is expecting another argument, add it
+        if ($this->definition->hasArgument($c)) {
+            $arg = $this->definition->getArgument($c);
+            $this->arguments[$arg->getName()] = $arg->isArray()? array($token) : $token;
+
+        // if last argument isArray(), append token to last argument
+        } elseif ($this->definition->hasArgument($c - 1) && $this->definition->getArgument($c - 1)->isArray()) {
+            $arg = $this->definition->getArgument($c - 1);
+            $this->arguments[$arg->getName()][] = $token;
 
-        $this->arguments[$this->definition->getArgument(count($this->arguments))->getName()] = $token;
+        // unexpected argument
+        } else {
+            throw new RuntimeException('Too many arguments.');
+        }
     }
 
     /**