|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Custom\Library\Drush\Commands; |
| 6 | + |
| 7 | +use Drupal\woot\AutowireTestService; |
| 8 | +use Drupal\woot\AutowireTestServiceInterface; |
| 9 | +use Drush\Attributes as CLI; |
| 10 | +use Drush\Boot\DrupalBootLevels; |
| 11 | +use Drush\Commands\AutowireTrait; |
| 12 | +use Drush\Commands\DrushCommands; |
| 13 | +use League\Container\ContainerAwareInterface; |
| 14 | +use League\Container\ContainerAwareTrait; |
| 15 | +use Symfony\Component\DependencyInjection\Attribute\Autowire; |
| 16 | + |
| 17 | +final class AutowireTestCommands extends DrushCommands |
| 18 | +{ |
| 19 | + use AutowireTrait; |
| 20 | + |
| 21 | + public function __construct( |
| 22 | + #[Autowire('a string as it is')] |
| 23 | + private readonly string $argListStringValue, |
| 24 | + #[Autowire(null, 'woot.autowire_test')] |
| 25 | + private readonly AutowireTestService $argListContainerService, |
| 26 | + #[Autowire(null, null, null, null, 'foo')] |
| 27 | + private readonly string $argListContainerParam, |
| 28 | + #[Autowire(value: 'a string as it is')] |
| 29 | + private readonly string $namedArgStringValue, |
| 30 | + #[Autowire(service: 'woot.autowire_test')] |
| 31 | + private readonly AutowireTestService $namedArgContainerService, |
| 32 | + #[Autowire(param: 'foo')] |
| 33 | + private readonly string $namedArgContainerParam, |
| 34 | + private readonly AutowireTestServiceInterface $noAutowireAttributeContainerService, |
| 35 | + ) { |
| 36 | + parent::__construct(); |
| 37 | + } |
| 38 | + |
| 39 | + #[CLI\Command(name: 'test_autowire:drupal-container')] |
| 40 | + #[CLI\Bootstrap(level: DrupalBootLevels::FULL)] |
| 41 | + #[CLI\Help(hidden: true)] |
| 42 | + public function drupal(): string |
| 43 | + { |
| 44 | + $values = []; |
| 45 | + $constructor = new \ReflectionMethod($this, '__construct'); |
| 46 | + foreach ($constructor->getParameters() as $param) { |
| 47 | + $values[] = (string) $this->{$param->getName()}; |
| 48 | + } |
| 49 | + return implode("\n", $values); |
| 50 | + } |
| 51 | + |
| 52 | + #[CLI\Command(name: 'test_autowire:drush-container')] |
| 53 | + #[CLI\Bootstrap(level: DrupalBootLevels::NONE)] |
| 54 | + #[CLI\Help(hidden: true)] |
| 55 | + public function drush(): string |
| 56 | + { |
| 57 | + $values = []; |
| 58 | + $constructor = new \ReflectionMethod($this, '__construct'); |
| 59 | + foreach ($constructor->getParameters() as $param) { |
| 60 | + $values[] = (string) $this->{$param->getName()}; |
| 61 | + } |
| 62 | + return implode("\n", $values); |
| 63 | + } |
| 64 | +} |
0 commit comments