diff --git a/src/Swoole/Delegators/TCPServerDelegator.php b/src/Swoole/Delegators/TCPServerDelegator.php index 5bcbf84..58d948f 100644 --- a/src/Swoole/Delegators/TCPServerDelegator.php +++ b/src/Swoole/Delegators/TCPServerDelegator.php @@ -11,6 +11,7 @@ use Queue\Swoole\Command\GetFailedMessagesCommand; use Queue\Swoole\Command\GetProcessedMessagesCommand; use Queue\Swoole\Command\GetQueuedMessagesCommand; +use Queue\Swoole\Exception\RuntimeException; use Swoole\Server as TCPSwooleServer; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\ArrayInput; @@ -23,6 +24,8 @@ use function array_shift; use function explode; use function ltrim; +use function method_exists; +use function sprintf; use function str_starts_with; use function trim; @@ -63,7 +66,15 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal $commandClass = $commandMap[$commandName]; $application = new Application(); $commandInstance = $container->get($commandClass); - $application->add($commandInstance); + if (method_exists($application, 'addCommand')) { + $application->addCommand($commandInstance); + } elseif (method_exists($application, 'add')) { + $application->add($commandInstance); + } else { + throw new RuntimeException( + sprintf('%s contains no "add" or "addCommand" method.', $application::class) + ); + } $parsedOptions = []; foreach ($args as $arg) {