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.
- [#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

View File

@ -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);
}
}
}