[Console][FrameworkBundle] Simplify using invokable commands when the component is used standalone#60394
Conversation
|
So we really need the extra method addInvokable() or could we handle this automatically? |
|
We cannot widen the argument type in |
e07ce18 to
5cf2a0d
Compare
|
We could remove it and handle it internally, couldn't we? Do we need to adjust addCommands() method as well? |
|
Cool, thanks for working on this.
@OskarStark If you mean removing the type declaration then it's a BC break too unfortunately, see https://3v4l.org/5dhmc. I'd prefer the invokable concept not to leak into public API though. What about adding |
758b85e to
2a19b9b
Compare
@chalasr I've made the changes you requested, please let me know what you think. |
weitzman
left a comment
There was a problem hiding this comment.
LGTM. This PR would be helpful for the Drush project (the main CLI for Drupal).
|
Wondering now that a new method is being added with support for both types of commands, shouldn’t we deprecate the |
| } | ||
| } | ||
|
|
||
| #[AsCommand(name: 'invokable')] |
There was a problem hiding this comment.
| #[AsCommand(name: 'invokable')] | |
| #[AsCommand(name: 'invokable', aliases: 'invk')] |
I did some testing on Drush and I am seeing the PR fail when an invokable command uses an alias. If you accept my suggestion above, hopefully the tests fail.
The problem is that $attribute->name is a pipe delimited string consisting of the name, followed by the aliases. See \Symfony\Component\Console\Attribute\AsCommand::__construct.
The code below helped me get past this bug. Not sure if there are better ways to solve it
$aliases = explode('|', $attribute->name);
$name = array_shift($aliases);
$commandHandler = (new Command($name))
->setAliases($aliases)
...
|
@yceruto 👍 for deprecating |
2a19b9b to
f2722a2
Compare
f2722a2 to
c3f55f3
Compare
|
@HypeMC it seems high-deps failures are related https://github.com/symfony/symfony/actions/runs/15518654102/job/43689003684?pr=60394, right? |
yceruto
left a comment
There was a problem hiding this comment.
@HypeMC it seems high-deps failures are related https://github.com/symfony/symfony/actions/runs/15518654102/job/43689003684?pr=60394, right?
Nevermind, it might be related to the 8.0 branch and should be resolved once this PR is merged into it.
c3f55f3 to
1886c10
Compare
|
Thank you @HypeMC. |
Symfony Console deprecate `add()` method and instead calls `addCommand()` method from `addCommands()`. This cause the application not to have the correct instance of `$laravel` property. PR: <symfony/symfony#60394> Signed-off-by: Mior Muhammad Zaki <[email protected]>
Symfony Console deprecate `add()` method and instead calls `addCommand()` method from `addCommands()`. This cause the application not to have the correct instance of `$laravel` property. PR: <symfony/symfony#60394> Signed-off-by: Mior Muhammad Zaki <[email protected]>
Symfony Console deprecate `add()` method and instead calls `addCommand()` method from `addCommands()`. This cause the application not to have the correct instance of `$laravel` property. PR: <symfony/symfony#60394> Signed-off-by: Mior Muhammad Zaki <[email protected]>
This PR was merged into the 6.4 branch. Discussion ---------- [Runtime] fix compatibility with Symfony 7.4 | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT Since #60394 using `add()` is deprecated. This means that our tests can trigger deprecations on older branches when the high deps job is run. This usually is not an issue as we silence them with the `SYMFONY_DEPRECATIONS_HELPER` env var. However, phpt tests are run in a child process where the deprecation error handler of the PHPUnit bridge doesn't step in. Thus, for them deprecations are not silenced leading to failures. We did something similar before in #60376. Commits ------- d39a7ac fix compatibility with Symfony 7.4
Inspired by #60389 (comment) .
This PR enables using invokable command when the component is used standalone: