Skip to content

Commit 4b6be19

Browse files
authored
Merge pull request #73 from dotkernel/issue-72
Issue #72: Replaced deprecated method
2 parents 47ccbfa + 679dad6 commit 4b6be19

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/Swoole/Delegators/TCPServerDelegator.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Queue\Swoole\Command\GetFailedMessagesCommand;
1212
use Queue\Swoole\Command\GetProcessedMessagesCommand;
1313
use Queue\Swoole\Command\GetQueuedMessagesCommand;
14+
use Queue\Swoole\Exception\RuntimeException;
1415
use Swoole\Server as TCPSwooleServer;
1516
use Symfony\Component\Console\Application;
1617
use Symfony\Component\Console\Input\ArrayInput;
@@ -23,6 +24,8 @@
2324
use function array_shift;
2425
use function explode;
2526
use function ltrim;
27+
use function method_exists;
28+
use function sprintf;
2629
use function str_starts_with;
2730
use function trim;
2831

@@ -63,7 +66,15 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal
6366
$commandClass = $commandMap[$commandName];
6467
$application = new Application();
6568
$commandInstance = $container->get($commandClass);
66-
$application->add($commandInstance);
69+
if (method_exists($application, 'addCommand')) {
70+
$application->addCommand($commandInstance);
71+
} elseif (method_exists($application, 'add')) {
72+
$application->add($commandInstance);
73+
} else {
74+
throw new RuntimeException(
75+
sprintf('%s contains no "add" or "addCommand" method.', $application::class)
76+
);
77+
}
6778

6879
$parsedOptions = [];
6980
foreach ($args as $arg) {

0 commit comments

Comments
 (0)