From 526231b72d4a0d22e3acead5a8407dd28058922a Mon Sep 17 00:00:00 2001 From: Degory Valentine Date: Fri, 25 Feb 2011 14:49:10 -0500 Subject: [PATCH 1/2] Fixed array argument parsing in ArgvInput. --- .../Component/Console/Input/ArgvInput.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Console/Input/ArgvInput.php b/src/Symfony/Component/Console/Input/ArgvInput.php index 256a15c9c4013..4c77ea3641693 100644 --- a/src/Symfony/Component/Console/Input/ArgvInput.php +++ b/src/Symfony/Component/Console/Input/ArgvInput.php @@ -150,11 +150,22 @@ protected function parseLongOption($token) */ 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.'); + } } /** From c3676e1764fae0d725041ad71dcf65c69eaeb87e Mon Sep 17 00:00:00 2001 From: Degory Valentine Date: Mon, 28 Feb 2011 10:40:32 -0500 Subject: [PATCH 2/2] added test to verify ArgvInput->parse() failure with array input definition --- src/Symfony/Component/Console/Input/ArgvInput.php | 2 +- .../Tests/Component/Console/Input/ArgvInputTest.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Input/ArgvInput.php b/src/Symfony/Component/Console/Input/ArgvInput.php index 4c77ea3641693..adebcd5c65377 100644 --- a/src/Symfony/Component/Console/Input/ArgvInput.php +++ b/src/Symfony/Component/Console/Input/ArgvInput.php @@ -164,7 +164,7 @@ protected function parseArgument($token) // unexpected argument } else { - throw new RuntimeException('Too many arguments.'); + throw new \RuntimeException('Too many arguments.'); } } diff --git a/tests/Symfony/Tests/Component/Console/Input/ArgvInputTest.php b/tests/Symfony/Tests/Component/Console/Input/ArgvInputTest.php index f9e701fc60dd4..9e339ffae6c46 100644 --- a/tests/Symfony/Tests/Component/Console/Input/ArgvInputTest.php +++ b/tests/Symfony/Tests/Component/Console/Input/ArgvInputTest.php @@ -135,6 +135,14 @@ public function testParser() $input = new TestInput(array('cli.php', '-fbbar')); $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL)))); $this->assertEquals(array('foo' => 'bbar', 'bar' => null), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and one of them takes a value'); + + try { + $input = new TestInput(array('cli.php', 'foo', 'bar', 'baz', 'bat')); + $input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::IS_ARRAY)))); + $this->assertEquals(array('name' => array('foo', 'bar', 'baz', 'bat')), $input->getArguments(), '->parse() parses array arguments'); + } catch (\RuntimeException $e) { + $this->assertNotEquals('Too many arguments.', $e->getMessage(), '->parse() parses array arguments'); + } } public function testGetFirstArgument() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy