Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Console] Revert "bug #41952 fix handling positional arguments" #41966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions 10 src/Symfony/Component/Console/Input/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@ public function getArguments()
*/
public function getArgument($name)
{
if (!$this->definition->hasArgument($name)) {
if (!$this->definition->hasArgument((string) $name)) {
throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
}

$name = \is_int($name) ? key(\array_slice($this->definition->getArguments(), $name, 1, true)) : $name;

return $this->arguments[$name] ?? $this->definition->getArgument($name)->getDefault();
}

Expand All @@ -120,12 +118,10 @@ public function getArgument($name)
*/
public function setArgument($name, $value)
{
if (!$this->definition->hasArgument($name)) {
if (!$this->definition->hasArgument((string) $name)) {
throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
}

$name = \is_int($name) ? key(\array_slice($this->definition->getArguments(), $name, 1, true)) : $name;

$this->arguments[$name] = $value;
}

Expand All @@ -134,7 +130,7 @@ public function setArgument($name, $value)
*/
public function hasArgument($name)
{
return $this->definition->hasArgument($name);
return $this->definition->hasArgument((string) $name);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions 8 src/Symfony/Component/Console/Input/InputInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getArguments();
/**
* Returns the argument value for a given argument name.
*
* @param string|int $name The InputArgument name or position
* @param string $name The argument name
*
* @return mixed
*
Expand All @@ -94,8 +94,8 @@ public function getArgument($name);
/**
* Sets an argument value by name.
*
* @param string|int $name The InputArgument name or position
* @param mixed $value The argument value
* @param string $name The argument name
* @param mixed $value The argument value
*
* @throws InvalidArgumentException When argument given doesn't exist
*/
Expand All @@ -104,7 +104,7 @@ public function setArgument($name, $value);
/**
* Returns true if an InputArgument object exists by name or position.
*
* @param string|int $name The InputArgument name or position
* @param string $name The InputArgument name or position
*
* @return bool true if the InputArgument object exists, false otherwise
*/
Expand Down
5 changes: 0 additions & 5 deletions 5 src/Symfony/Component/Console/Tests/Input/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ public function testArguments()
$input = new ArrayInput(['name' => 'foo'], new InputDefinition([new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default')]));
$this->assertEquals('default', $input->getArgument('bar'), '->getArgument() returns the default value for optional arguments');
$this->assertEquals(['name' => 'foo', 'bar' => 'default'], $input->getArguments(), '->getArguments() returns all argument values, even optional ones');

$input = new ArrayInput(['arg1' => 'foo'], new InputDefinition([new InputArgument('arg1'), new InputArgument('arg2')]));
$input->setArgument(1, 'bar');
$this->assertEquals('bar', $input->getArgument(1));
$this->assertEquals(['arg1' => 'foo', 'arg2' => 'bar'], $input->getArguments());
}

public function testSetInvalidArgument()
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.