-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Invokable command adjustments #59493
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,10 @@ public function __construct(?string $name = null) | |
$this->setDescription(static::getDefaultDescription() ?? ''); | ||
} | ||
|
||
if (\is_callable($this)) { | ||
$this->code = new InvokableCommand($this, $this(...)); | ||
} | ||
|
||
$this->configure(); | ||
} | ||
|
||
|
@@ -164,9 +168,6 @@ public function isEnabled(): bool | |
*/ | ||
protected function configure() | ||
{ | ||
if (!$this->code && \is_callable($this)) { | ||
$this->code = new InvokableCommand($this, $this(...)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to the constructor to allow overriding the |
||
} | ||
|
||
/** | ||
|
@@ -312,22 +313,6 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti | |
*/ | ||
public function setCode(callable $code): static | ||
{ | ||
if ($code instanceof \Closure) { | ||
$r = new \ReflectionFunction($code); | ||
if (null === $r->getClosureThis()) { | ||
set_error_handler(static function () {}); | ||
try { | ||
if ($c = \Closure::bind($code, $this)) { | ||
$code = $c; | ||
} | ||
} finally { | ||
restore_error_handler(); | ||
} | ||
} | ||
} else { | ||
$code = $code(...); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to |
||
|
||
$this->code = new InvokableCommand($this, $code, triggerDeprecations: true); | ||
|
||
return $this; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
$input->hasArgument($this->name)
as it's better to get the "argument does not exist" exception than a TypeError or just null (if nullable)