diff --git a/CHANGELOG-3.1.md b/CHANGELOG-3.1.md index 3057f2f45..e1896d778 100644 --- a/CHANGELOG-3.1.md +++ b/CHANGELOG-3.1.md @@ -7,6 +7,10 @@ - [#6579](https://github.com/hyperf/hyperf/pull/6579) Added `now()` and `today()` helper functions. - [#6590](https://github.com/hyperf/hyperf/pull/6590) Added `--graceful` to migrateCommand. +## Fixed + +- [#6593](https://github.com/hyperf/hyperf/pull/6593) Fixed the error when register multi `AsCommand`. + # v3.1.12 - 2024-03-07 ## Fixed diff --git a/src/command/src/Listener/RegisterCommandListener.php b/src/command/src/Listener/RegisterCommandListener.php index d04b704ed..17d21c720 100644 --- a/src/command/src/Listener/RegisterCommandListener.php +++ b/src/command/src/Listener/RegisterCommandListener.php @@ -72,24 +72,28 @@ class RegisterCommandListener implements ListenerInterface $commands = AnnotationCollector::getMethodsByAnnotation(AsCommandAnnotation::class); foreach ($commands as $metadata) { - /** @var AsCommandAnnotation $annotation */ - $annotation = $metadata['annotation']; - $command = new AsCommand( - $this->container, - $annotation->signature, - $metadata['class'], - $metadata['method'], - ); + /** @var \Hyperf\Di\Annotation\MultipleAnnotation $multiAnnotation */ + $multiAnnotation = $metadata['annotation']; + /** @var AsCommandAnnotation[] $annotations */ + $annotations = $multiAnnotation->toAnnotations(); + foreach ($annotations as $annotation) { + $command = new AsCommand( + $this->container, + $annotation->signature, + $metadata['class'], + $metadata['method'], + ); - if ($annotation->description) { - $command->setDescription($annotation->description); - } - if ($annotation->aliases) { - $command->setAliases($annotation->aliases); - } + if ($annotation->description) { + $command->setDescription($annotation->description); + } + if ($annotation->aliases) { + $command->setAliases($annotation->aliases); + } - $this->container->set($annotation->id, $command); - $this->appendConfig('commands', $annotation->id); + $this->container->set($annotation->id, $command); + $this->appendConfig('commands', $annotation->id); + } } }