Skip to content
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

[11.x] Fix command alias registration and usage. #50617

Merged
merged 5 commits into from
Mar 19, 2024

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Mar 18, 2024

Our commands are not currently able to be run via their aliases defined in the class property. This is due to the AsCommand attribute.

composer create-project laravel/laravel command-test && \
    cd command-test && \
    php artisan session:table

Attribute with: name

#[AsCommand(name: 'make:session-table')]
class SessionTableCommand extends MigrationGeneratorCommand
{
    protected $name = 'make:session-table';

    protected $aliases = ['session:table'];
php artisan make:session-table ✅
php artisan session:table ❌

Attribute with: name, aliases

#[AsCommand(name: 'make:session-table', aliases: ['session:table')]
class SessionTableCommand extends MigrationGeneratorCommand
{
    protected $name = 'make:session-table';

    protected $aliases = ['session:table'];
php artisan make:session-table ✅
php artisan session:table ✅

What does the AsCommand attribute do for Laravel?

Applying the attribute allows us to not instantiate a command when running a different command.

For example, if we have the following command with no attribute:

class SessionTableCommand extends MigrationGeneratorCommand
{
    protected $name = 'make:session-table';

    protected $aliases = ['session:table'];

and we proceed to run php artisan view:clear the SessionTableCommand will be instantiated even though it is not needed.

Commands are always instantiated when calling php artisan list

Ecosystem PRs

I believe I've updated the most important open source commands to make them lazy and align across the ecosystem. I've also ensured that aliases are defined where needed.

Cannot update tinker or vapor-core due to them supporting older version of symfony/console

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@timacdonald timacdonald changed the title [11.x] Command loading [11.x] Fix command alias registration and usage. Mar 18, 2024
@taylorotwell taylorotwell merged commit 1ce56c8 into laravel:11.x Mar 19, 2024
28 checks passed
@timacdonald timacdonald deleted the command-loading branch March 20, 2024 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants