Feature: #89139 - Add dependency injection support for console commands
See forge#89139
Description
Support for dependency injection in console commands has been added.
Command dependencies can now be injected via constructor or other injection techniques.
Therefore, a new dependency injection tag console.
has been added.
Commands tagged with console.
are lazy loaded. That means they will only be
instantiated when they are actually executed, when the help
subcommand is executed,
or when available schedulable commands are iterated.
The legacy command definition format Configuration/
has been marked as deprecated.
Impact
It is recommended to configure dependency injection tags for all commands, as the legacy command
definition format Configuration/
will be removed in TYPO3 v11.
Commands that have been configured via console.
tag override legacy commands from
Configuration/
without triggering a PHP E_
error for those commands.
Backwards compatibility with older TYPO3 version can be achieved by specifying both variants,
legacy configuration in Configuration/
and new configuration via
console.
tag.
Usage
Add the console.
tag to command classes.
Use the tag attribute command
to specify the command name.
The optional tag attribute schedulable
may be set to false
to exclude the command from the TYPO3 scheduler.
your_
services:
_defaults:
autowire: true
autoconfigure: true
public: false
MyVendor\MyExt\Command\FooCommand:
tags:
- name: 'console.command'
command: 'my:command'
schedulable: false
Command aliases are to be configured as separate tags.
The optional tag attribute alias
should be set to true for alias commands.
MyVendor\MyExt\Command\BarCommand:
tags:
- name: 'console.command'
command: 'my:bar'
- name: 'console.command'
command: 'my:old-bar-command'
alias: true
schedulable: false