Fixed the error when register multi AsCommand (#6593)

This commit is contained in:
Deeka Wong 2024-03-14 10:26:59 +08:00 committed by GitHub
parent 0e7435db45
commit 052cce3114
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 16 deletions

View File

@ -7,6 +7,10 @@
- [#6579](https://github.com/hyperf/hyperf/pull/6579) Added `now()` and `today()` helper functions. - [#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. - [#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 # v3.1.12 - 2024-03-07
## Fixed ## Fixed

View File

@ -72,24 +72,28 @@ class RegisterCommandListener implements ListenerInterface
$commands = AnnotationCollector::getMethodsByAnnotation(AsCommandAnnotation::class); $commands = AnnotationCollector::getMethodsByAnnotation(AsCommandAnnotation::class);
foreach ($commands as $metadata) { foreach ($commands as $metadata) {
/** @var AsCommandAnnotation $annotation */ /** @var \Hyperf\Di\Annotation\MultipleAnnotation $multiAnnotation */
$annotation = $metadata['annotation']; $multiAnnotation = $metadata['annotation'];
$command = new AsCommand( /** @var AsCommandAnnotation[] $annotations */
$this->container, $annotations = $multiAnnotation->toAnnotations();
$annotation->signature, foreach ($annotations as $annotation) {
$metadata['class'], $command = new AsCommand(
$metadata['method'], $this->container,
); $annotation->signature,
$metadata['class'],
$metadata['method'],
);
if ($annotation->description) { if ($annotation->description) {
$command->setDescription($annotation->description); $command->setDescription($annotation->description);
} }
if ($annotation->aliases) { if ($annotation->aliases) {
$command->setAliases($annotation->aliases); $command->setAliases($annotation->aliases);
} }
$this->container->set($annotation->id, $command); $this->container->set($annotation->id, $command);
$this->appendConfig('commands', $annotation->id); $this->appendConfig('commands', $annotation->id);
}
} }
} }