Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -22,25 +22,23 @@ class Argument | ||
{ | ||
private const ALLOWED_TYPES = ['string', 'bool', 'int', 'float', 'array']; | ||
private string|bool|int|float|array|null $default = null; | ||
private array|\Closure $suggestedValues; | ||
private ?int $mode = null; | ||
/** | ||
* Represents a console command <argument> definition. | ||
* | ||
* If unset, the `name`value will be inferred from the parameter definition. | ||
* | ||
* @param array<string|Suggestion>|callable(CompletionInput):list<string|Suggestion> $suggestedValues The values used for input completion | ||
*/ | ||
public function __construct( | ||
public string $name = '', | ||
public string $description = '', | ||
array|callable $suggestedValues = [], | ||
) { | ||
$this->suggestedValues = \is_callable($suggestedValues) ? $suggestedValues(...) : $suggestedValues; | ||
} | ||
/** | ||
@@ -70,13 +68,13 @@ public static function tryFrom(\ReflectionParameter $parameter): ?self | ||
$self->name = $name; | ||
} | ||
$self->default = $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null; | ||
$self->mode = $parameter->isDefaultValueAvailable() || $parameter->allowsNull() ? InputArgument::OPTIONAL : InputArgument::REQUIRED; | ||
if ('array' === $parameterTypeName) { | ||
$self->mode |= InputArgument::IS_ARRAY; | ||
} | ||
if (\is_array($self->suggestedValues) && !\is_callable($self->suggestedValues) && 2 === \count($self->suggestedValues) && ($instance = $parameter->getDeclaringFunction()->getClosureThis()) && $instance::class === $self->suggestedValues[0] && \is_callable([$instance, $self->suggestedValues[1]])) { | ||
$self->suggestedValues = [$instance, $self->suggestedValues[1]]; | ||
} | ||
@@ -99,6 +97,6 @@ public function toInputArgument(): InputArgument | ||
*/ | ||
public function resolveValue(InputInterface $input): mixed | ||
{ | ||
return $input->getArgument($this->name); | ||
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. removed | ||
} | ||
} |
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() | ||
{ | ||
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 | ||
{ | ||
MemberAuthor 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; | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.