minor #35734 [Console] Inline exact-match handling with 4.4 (chalasr)
This PR was merged into the 3.4 branch.
Discussion
----------
[Console] Inline exact-match handling with 4.4
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | no
| New feature? | no
| Deprecations? | no
| Tickets | https://github.com/symfony/symfony/pull/35696#issuecomment-585830029
| License | MIT
| Doc PR | -
This reduces the patch for #35696 (not released yet), inlining 3.4's code with 4.4 which was not impacted by the fixed bug. The reverted logic was useless starting from 4.4.
Thanks @stof for the hint.
Commits
-------
e13470c823
[Console] Inline exact-match handling with 4.4
This commit is contained in:
commit
334f0205d0
@ -608,6 +608,10 @@ class Application
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->has($name)) {
|
||||||
|
return $this->get($name);
|
||||||
|
}
|
||||||
|
|
||||||
$allCommands = $this->commandLoader ? array_merge($this->commandLoader->getNames(), array_keys($this->commands)) : array_keys($this->commands);
|
$allCommands = $this->commandLoader ? array_merge($this->commandLoader->getNames(), array_keys($this->commands)) : array_keys($this->commands);
|
||||||
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $name);
|
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $name);
|
||||||
$commands = preg_grep('{^'.$expr.'}', $allCommands);
|
$commands = preg_grep('{^'.$expr.'}', $allCommands);
|
||||||
@ -645,15 +649,7 @@ class Application
|
|||||||
// filter out aliases for commands which are already on the list
|
// filter out aliases for commands which are already on the list
|
||||||
if (\count($commands) > 1) {
|
if (\count($commands) > 1) {
|
||||||
$commandList = $this->commandLoader ? array_merge(array_flip($this->commandLoader->getNames()), $this->commands) : $this->commands;
|
$commandList = $this->commandLoader ? array_merge(array_flip($this->commandLoader->getNames()), $this->commands) : $this->commands;
|
||||||
|
$commands = array_unique(array_filter($commands, function ($nameOrAlias) use (&$commandList, $commands, &$aliases) {
|
||||||
if (isset($commandList[$name])) {
|
|
||||||
return $this->get($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($commands as $k => $nameOrAlias) {
|
|
||||||
if ($nameOrAlias === $name) {
|
|
||||||
return $this->get($nameOrAlias);
|
|
||||||
}
|
|
||||||
if (!$commandList[$nameOrAlias] instanceof Command) {
|
if (!$commandList[$nameOrAlias] instanceof Command) {
|
||||||
$commandList[$nameOrAlias] = $this->commandLoader->get($nameOrAlias);
|
$commandList[$nameOrAlias] = $this->commandLoader->get($nameOrAlias);
|
||||||
}
|
}
|
||||||
@ -662,14 +658,8 @@ class Application
|
|||||||
|
|
||||||
$aliases[$nameOrAlias] = $commandName;
|
$aliases[$nameOrAlias] = $commandName;
|
||||||
|
|
||||||
if ($commandName === $nameOrAlias || !\in_array($commandName, $commands)) {
|
return $commandName === $nameOrAlias || !\in_array($commandName, $commands);
|
||||||
continue;
|
}));
|
||||||
}
|
|
||||||
|
|
||||||
unset($commands[$k]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$commands = array_unique($commands);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$exact = \in_array($name, $commands, true) || isset($aliases[$name]);
|
$exact = \in_array($name, $commands, true) || isset($aliases[$name]);
|
||||||
|
Reference in New Issue
Block a user