Skip to content

Allow lazy loading of commands (v2) - #63

Open
benr77 wants to merge 1 commit into
php-task:masterfrom
benr77:lazy-loading-commands
Open

Allow lazy loading of commands (v2)#63
benr77 wants to merge 1 commit into
php-task:masterfrom
benr77:lazy-loading-commands

Conversation

@benr77

@benr77 benr77 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

My first PR to fix this was only half the job. In order to properly enable lazy loading of commands, it is also necessary to NOT pass the command name into the command constructor, as well as the existing fix to specify the "command" attribute on the XML tag element.

@alexander-schranz

Copy link
Copy Markdown
Member

Unsure about this as its technically a bc break when we change the constructor.

@benr77

benr77 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Nobody should be calling the constructor of these command classes - it's only ever done by the framework. But yes technically it's a BC break.

Installing it without this PR throws exceptions on cache:clear etc. How about a new major or minor version bump?

@alexander-schranz

Copy link
Copy Markdown
Member

The classes are not final or internal so somebody could extend it.

What happens if we instead of remove the parameter <argument type="string">task:schedule:system-tasks</argument> set it to null in the service definiton: <argument/> / <argument>null</argument> (not sure about the syntax).

Would then lazy not work again and there would not be any bc break in the class?

Else yes a new major would be required, minors should also not introduce bc breaks here.

@benr77

benr77 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

I think the critical bit needed to enable lazy loading is to NOT pass the string $name into parent::__construct() - so the command constructor can keep receiving the parameter, but we'll send null via the service definition. I will try this later and push some changes if it works.

@benr77
benr77 force-pushed the lazy-loading-commands branch from ea41abb to bd51920 Compare August 20, 2026 14:54
@benr77

benr77 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@alexander-schranz Your suggestion works fine - thanks. This is ready to merge if you are happy.

Passing a string means Symfony cannot lazily load the commands.
@benr77
benr77 force-pushed the lazy-loading-commands branch from bd51920 to 9da654e Compare August 20, 2026 15:20
@benr77

benr77 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

For reference, <argument/> resolves to an empty string, which failed some checks on PHP 8.0 and 8.1 but was acceptable on more recent PHP. Using <argument>null</argument> resolves to an actual PHP null, which is what I've used here.

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.

2 participants