-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
Describe the bug
The AutowireTrait collects the constructor arguments based on static, but the instance is created from self.
- https://github.com/drush-ops/drush/blob/13.7.0/src/Commands/AutowireTrait.php#L43
- https://git.drupalcode.org/project/drupal/-/blob/11.2.x/core/lib/Drupal/Core/DependencyInjection/AutowireTrait.php?ref_type=heads#L48
Drupal 11.2.8 uses static in both places.
To Reproduce
// NOT IN a directory where command discovery could find it.
abstract class MyCommandBase extends \Symfony\Component\Console\Command\Command {
use \Drush\Commands\AutowireTrait;
public function __construct(
#[Autowire('logger')]
protected LoggerInterface $logger,
) {
parent::__construct();
}
// ...
}
// IN a directory where command discover can find it.
[\Symfony\Component\Console\Attribute\AsCommand(
name: 'my:foo',
description: 'my desc',
)]
final class FooCommand extends MyCommandBase {
// ...
}Expected behavior
Create a new command
Actual behavior
Fatal error exception:
Cannot instantiate abstract class MyCommandBase
Workaround
Every command MUST HAVE its own __construct() or use \Drush\Commands\AutowireTrait;.
System Configuration
| Q | A |
|---|---|
| Drush version? | 13.7.0 |
| Drupal version? | 11.2.8 |
| PHP version | 8.3.x |
| OS? | Linux |
Metadata
Metadata
Assignees
Labels
No labels