mezzio-swoole 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * @deprecated To be removed with Shlink 3.0.0
  5. * This script is provided to keep backwards compatibility on how to run shlink with swoole while being still able to
  6. * update to mezzio/mezzio-swoole 3.x
  7. */
  8. declare(strict_types=1);
  9. namespace Mezzio\Swoole\Command;
  10. use Laminas\ServiceManager\ServiceManager;
  11. use PackageVersions\Versions;
  12. use Symfony\Component\Console\Application as CommandLine;
  13. use Symfony\Component\Console\Command\Command;
  14. use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
  15. use function explode;
  16. use function Functional\filter;
  17. use function str_starts_with;
  18. use function strstr;
  19. /** @var ServiceManager $container */
  20. $container = require __DIR__ . '/../../config/container.php';
  21. $version = strstr(Versions::getVersion('mezzio/mezzio-swoole'), '@', true);
  22. $commandsPrefix = 'mezzio:swoole:';
  23. $commands = filter(
  24. $container->get('config')['laminas-cli']['commands'] ?? [],
  25. fn ($c, string $command) => str_starts_with($command, $commandsPrefix),
  26. );
  27. $registeredCommands = [];
  28. foreach ($commands as $newName => $commandServiceName) {
  29. [, $oldName] = explode($commandsPrefix, $newName);
  30. $registeredCommands[$oldName] = $commandServiceName;
  31. $container->addDelegator($commandServiceName, static function ($c, $n, callable $factory) use ($oldName) {
  32. /** @var Command $command */
  33. $command = $factory();
  34. $command->setAliases([$oldName]);
  35. return $command;
  36. });
  37. }
  38. $commandLine = new CommandLine('Mezzio web server', $version);
  39. $commandLine->setAutoExit(true);
  40. $commandLine->setCommandLoader(new ContainerCommandLoader($container, $registeredCommands));
  41. $commandLine->run();