Skip to content

Commit

Permalink
Fix Environment::isArgumentDefined() returns false in case of handl…
Browse files Browse the repository at this point in the history
…er called with $argv value
  • Loading branch information
ElGigi committed Nov 28, 2024
1 parent 6ce5805 commit bc6f3a1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. This projec
to [Semantic Versioning] (http://semver.org/). For change log format,
use [Keep a Changelog] (http://keepachangelog.com/).

## [2.2.1] - 2024-11-28

### Fixed

- `Environment::isArgumentDefined()` return false in case of handler called with $argv value

## [2.2.0] - 2022-12-02

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function handle(?array $argv = null): int
$this->addArguments($command);
$this->console->getArgumentsManager()->parse($argv);

return $commandObj->run(new Environment($this->console, $command));
return $commandObj->run(new Environment($this->console, $command, $argv));
} catch (Throwable $exception) {
$this->printException($exception);
return 1;
Expand Down
5 changes: 3 additions & 2 deletions src/Console/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Environment
{
public function __construct(
protected Console $console,
protected CommandDeclaration $command
protected CommandDeclaration $command,
protected ?array $argv = null,
) {
}

Expand Down Expand Up @@ -97,6 +98,6 @@ public function isArgumentDefined(string $name, ?array $argv = null): bool
throw InvalidArgumentException::unknown($name, $this->command->getClass());
}

return $this->console->arguments->defined($name, $argv);
return $this->console->arguments->defined($name, $argv ?? $this->argv);
}
}

0 comments on commit bc6f3a1

Please sign in to comment.