Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Invokable command loader#62311

Unanswered
acelaya asked this question inQ&A
Nov 5, 2025· 1 comments· 2 replies
Discussion options

I have been lately usinginvokable commands in mysymfony/console applications, and it works great. It's a very good approach, and I plan to bet further on this onceSymfony 7.4 is released.

The only limitation I have found so far is that I'm using theContainerCommandLoader to dynamically load my commands from a container, but since theget method has aCommand return type, I need to make my invokable commands extend fromCommand even if I'm not using any of its methods.

I wanted to know if there are any plans to provide alternative ways to lazy-load commands without having to extendCommand.

You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

yceruto
Nov 5, 2025
Collaborator

Hey@acelaya, just wondering what kind of error you're seeing in this case..

when an invokable command is defined without extendingCommand, it's automatically wrapped into aCommand instance during the compiler pass, so retrieving it through theContainerCommandLoader should still return a validCommand instance.

since 7.4, you can also get the invokable command class usingCommand::getCode().

You must be logged in to vote
2 replies
@acelaya
Comment options

when an invokable command is defined without extendingCommand, it's automatically wrapped into aCommand instance during the compiler pass

I'm assuming this happens when using Symfony's default dependency injection container? I'm using a different PSR-11 container, so I guess that's the reason.

I basically get a runtimeTypeError because theget method expects aCommand to be returned, but calling$this->container->get($this->commandMap[$name]); doesn't do that in my case.

TypeError: Symfony\Component\Console\CommandLoader\ContainerCommandLoader::get(): Return value must be of type Symfony\Component\Console\Command\Command, Shlinkio\Shlink\CLI\Command\Api\InitialApiKeyCommand returned in /home/shlink/vendor/symfony/console/CommandLoader/ContainerCommandLoader.php on line 40

Could you point me to the place where this wrapping is done? I might be able to implement a small piece of logic doing something similar by implementing a custom command loader.

@yceruto
Comment options

ycerutoNov 5, 2025
Collaborator

Yes, everything is in AddConsoleCommandPass

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@acelaya@yceruto

[8]ページ先頭

©2009-2025 Movatter.jp