From e3ff4471529f1a96d77780c23f11798c4b127df7 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 14 Jan 2021 20:19:38 +0100 Subject: [PATCH] Updated to mezzio-swoole 3 --- .gitignore | 1 + README.md | 4 +-- bin/test/run-api-tests.sh | 6 ++-- composer.json | 2 +- data/infra/examples/shlink-daemon.sh | 2 +- data/infra/swoole.Dockerfile | 2 +- docker/docker-entrypoint.sh | 2 +- vendor/bin/mezzio-swoole | 45 ++++++++++++++++++++++++++++ 8 files changed, 55 insertions(+), 9 deletions(-) create mode 100755 vendor/bin/mezzio-swoole diff --git a/.gitignore b/.gitignore index 8cfea409..bd42bc71 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ build composer.lock composer.phar vendor/ +!vendor/bin/mezzio-swoole data/database.sqlite data/shlink-tests.db data/GeoLite2-City.mmdb diff --git a/README.md b/README.md index a54c20c8..533d5b50 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ Once Shlink is configured, you need to expose it to the web, either by using a t First you need to install the swoole PHP extension with [pecl](https://pecl.php.net/package/swoole), `pecl install swoole`. - Once installed, it's actually pretty easy to get shlink up and running with swoole. Run `./vendor/bin/mezzio-swoole start -d` and you will get shlink running on port 8080. + Once installed, it's actually pretty easy to get shlink up and running with swoole. Run `./vendor/bin/laminas mezzio:swoole:start -d` and you will get shlink running on port 8080. However, by doing it this way, you are loosing all the access logs, and the service won't be automatically run if the server has to be restarted. @@ -147,7 +147,7 @@ Once Shlink is configured, you need to expose it to the web, either by using a t # Description: Shlink non-blocking server with swoole ### END INIT INFO - SCRIPT=/path/to/shlink/vendor/bin/mezzio-swoole\ start + SCRIPT=/path/to/shlink/vendor/bin/laminas\ mezzio:swoole:start RUNAS=root PIDFILE=/var/run/shlink_swoole.pid diff --git a/bin/test/run-api-tests.sh b/bin/test/run-api-tests.sh index f3236d1b..06708d18 100755 --- a/bin/test/run-api-tests.sh +++ b/bin/test/run-api-tests.sh @@ -4,16 +4,16 @@ export DB_DRIVER=mysql export TEST_ENV=api # Try to stop server just in case it hanged in last execution -vendor/bin/mezzio-swoole stop +vendor/bin/laminas mezzio:swoole:stop echo 'Starting server...' -vendor/bin/mezzio-swoole start -d +vendor/bin/laminas mezzio:swoole:start -d sleep 2 vendor/bin/phpunit --order-by=random -c phpunit-api.xml --testdox --colors=always --log-junit=build/coverage-api/junit.xml $* testsExitCode=$? -vendor/bin/mezzio-swoole stop +vendor/bin/laminas mezzio:swoole:stop # Exit this script with the same code as the tests. If tests failed, this script has to fail exit $testsExitCode diff --git a/composer.json b/composer.json index 70454cfa..f7835b3f 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "mezzio/mezzio-fastroute": "^3.1", "mezzio/mezzio-helpers": "^5.3", "mezzio/mezzio-problem-details": "^1.1", - "mezzio/mezzio-swoole": "^2.6.4", + "mezzio/mezzio-swoole": "^3.1", "monolog/monolog": "^2.0", "nikolaposa/monolog-factory": "^3.1", "ocramius/proxy-manager": "^2.11", diff --git a/data/infra/examples/shlink-daemon.sh b/data/infra/examples/shlink-daemon.sh index a18ca65a..ce905721 100644 --- a/data/infra/examples/shlink-daemon.sh +++ b/data/infra/examples/shlink-daemon.sh @@ -8,7 +8,7 @@ # Description: Shlink non-blocking server with swoole ### END INIT INFO -SCRIPT=/path/to/shlink/vendor/bin/mezzio-swoole\ start +SCRIPT=/path/to/shlink/vendor/bin/laminas\ mezzio:swoole:start RUNAS=root PIDFILE=/var/run/shlink_swoole.pid diff --git a/data/infra/swoole.Dockerfile b/data/infra/swoole.Dockerfile index b6bfb5a7..bb1f084c 100644 --- a/data/infra/swoole.Dockerfile +++ b/data/infra/swoole.Dockerfile @@ -95,4 +95,4 @@ CMD \ if [[ ! -d "./vendor" ]]; then /usr/local/bin/composer install ; fi && \ # When restarting the container, swoole might think it is already in execution # This forces the app to be started every second until the exit code is 0 - until php ./vendor/bin/mezzio-swoole start; do sleep 1 ; done + until php ./vendor/bin/laminas mezzio:swoole:start; do sleep 1 ; done diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 055e315f..df480d2f 100644 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -17,4 +17,4 @@ php vendor/doctrine/orm/bin/doctrine.php orm:clear-cache:metadata -n -q # When restarting the container, swoole might think it is already in execution # This forces the app to be started every second until the exit code is 0 -until php vendor/mezzio/mezzio-swoole/bin/mezzio-swoole start; do sleep 1 ; done +until php vendor/bin/laminas mezzio:swoole:start; do sleep 1 ; done diff --git a/vendor/bin/mezzio-swoole b/vendor/bin/mezzio-swoole new file mode 100755 index 00000000..d28100bf --- /dev/null +++ b/vendor/bin/mezzio-swoole @@ -0,0 +1,45 @@ +#!/usr/bin/env php +get('config')['laminas-cli']['commands'] ?? []; +$registeredCommands = []; + +foreach ($commands as $newName => $commandServiceName) { + [, $oldName] = explode('mezzio:swoole:', $newName); + $registeredCommands[$oldName] = $commandServiceName; + + $container->addDelegator($commandServiceName, static function ($c, $n, callable $factory) use ($oldName) { + /** @var Command $command */ + $command = $factory(); + $command->setAliases([$oldName]); + + return $command; + }); +} + +$commandLine = new CommandLine('Mezzio web server', $version); +$commandLine->setAutoExit(true); +$commandLine->setCommandLoader(new ContainerCommandLoader($container, $registeredCommands)); +$commandLine->run();