From d086131630556a080d8947bac5792e7d16015e1d Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 19 Jul 2019 19:54:39 +0200 Subject: [PATCH] Moved all event-dispatching stuff to its own module --- composer.json | 10 ++++--- config/autoload/event_dispatcher.global.php | 20 -------------- config/config.php | 4 +-- module/Common/functions/functions.php | 7 ----- .../config/event_dispatcher.config.php | 27 +++++++++++++++++++ .../config/task_runner.config.php | 6 ++--- .../EventDispatcher/functions/functions.php | 11 ++++++++ .../src/Async}/Task.php | 2 +- .../src/Async}/TaskRunner.php | 2 +- .../src/Async}/TaskRunnerDelegator.php | 2 +- .../src/Async}/TaskRunnerFactory.php | 2 +- module/EventDispatcher/src/ConfigProvider.php | 15 +++++++++++ .../src/Listener}/AsyncEventListener.php | 3 ++- .../src/Listener}/ListenerProviderFactory.php | 4 +-- .../Listener}/ListenerProviderFactoryTest.php | 4 +-- phpunit.xml.dist | 4 +-- 16 files changed, 77 insertions(+), 46 deletions(-) delete mode 100644 config/autoload/event_dispatcher.global.php create mode 100644 module/EventDispatcher/config/event_dispatcher.config.php rename module/{Common => EventDispatcher}/config/task_runner.config.php (56%) create mode 100644 module/EventDispatcher/functions/functions.php rename module/{Common/src/EventDispatcher => EventDispatcher/src/Async}/Task.php (93%) rename module/{Common/src/EventDispatcher => EventDispatcher/src/Async}/TaskRunner.php (96%) rename module/{Common/src/EventDispatcher => EventDispatcher/src/Async}/TaskRunnerDelegator.php (94%) rename module/{Common/src/EventDispatcher => EventDispatcher/src/Async}/TaskRunnerFactory.php (89%) create mode 100644 module/EventDispatcher/src/ConfigProvider.php rename module/{Common/src/EventDispatcher => EventDispatcher/src/Listener}/AsyncEventListener.php (84%) rename module/{Common/src/EventDispatcher => EventDispatcher/src/Listener}/ListenerProviderFactory.php (93%) rename module/{Common/test/EventDispatcher => EventDispatcher/test/Listener}/ListenerProviderFactoryTest.php (95%) diff --git a/composer.json b/composer.json index ba72716d..e6e20989 100644 --- a/composer.json +++ b/composer.json @@ -53,6 +53,7 @@ "require-dev": { "devster/ubench": "^2.0", "doctrine/data-fixtures": "^1.3", + "eaglewu/swoole-ide-helper": "dev-master", "filp/whoops": "^2.0", "infection/infection": "^0.12.2", "phpstan/phpstan": "^0.11.2", @@ -70,10 +71,12 @@ "Shlinkio\\Shlink\\CLI\\": "module/CLI/src", "Shlinkio\\Shlink\\Rest\\": "module/Rest/src", "Shlinkio\\Shlink\\Core\\": "module/Core/src", - "Shlinkio\\Shlink\\Common\\": "module/Common/src" + "Shlinkio\\Shlink\\Common\\": "module/Common/src", + "Shlinkio\\Shlink\\EventDispatcher\\": "module/EventDispatcher/src" }, "files": [ - "module/Common/functions/functions.php" + "module/Common/functions/functions.php", + "module/EventDispatcher/functions/functions.php" ] }, "autoload-dev": { @@ -88,7 +91,8 @@ "ShlinkioTest\\Shlink\\Common\\": [ "module/Common/test", "module/Common/test-db" - ] + ], + "ShlinkioTest\\Shlink\\EventDispatcher\\": "module/EventDispatcher/test" } }, "scripts": { diff --git a/config/autoload/event_dispatcher.global.php b/config/autoload/event_dispatcher.global.php deleted file mode 100644 index 53964152..00000000 --- a/config/autoload/event_dispatcher.global.php +++ /dev/null @@ -1,20 +0,0 @@ - [ - 'factories' => [ - Psr\ListenerProviderInterface::class => Common\EventDispatcher\ListenerProviderFactory::class, - ], - 'aliases' => [ - Psr\EventDispatcherInterface::class => Phly\EventDispatcher::class, - ], - ], - -]; diff --git a/config/config.php b/config/config.php index e10d3c1e..f09bb9f6 100644 --- a/config/config.php +++ b/config/config.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace Shlinkio\Shlink; use Acelaya\ExpressiveErrorHandler; -use Phly\EventDispatcher; use Zend\ConfigAggregator; use Zend\Expressive; + use function Shlinkio\Shlink\Common\env; return (new ConfigAggregator\ConfigAggregator([ @@ -16,11 +16,11 @@ return (new ConfigAggregator\ConfigAggregator([ Expressive\Plates\ConfigProvider::class, Expressive\Swoole\ConfigProvider::class, ExpressiveErrorHandler\ConfigProvider::class, - EventDispatcher\ConfigProvider::class, Common\ConfigProvider::class, Core\ConfigProvider::class, CLI\ConfigProvider::class, Rest\ConfigProvider::class, + EventDispatcher\ConfigProvider::class, new ConfigAggregator\PhpFileProvider('config/autoload/{{,*.}global,{,*.}local}.php'), new ConfigAggregator\ZendConfigProvider('config/params/{generated_config.php,*.config.{php,json}}'), env('APP_ENV') === 'test' diff --git a/module/Common/functions/functions.php b/module/Common/functions/functions.php index 17856af2..485df607 100644 --- a/module/Common/functions/functions.php +++ b/module/Common/functions/functions.php @@ -3,8 +3,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common; -use Swoole\Http\Server as HttpServer; - use const JSON_ERROR_NONE; use function getenv; @@ -61,8 +59,3 @@ function json_decode(string $json, int $depth = 512, int $options = 0): array return $data; } - -function asyncListener(HttpServer $server, string $regularListenerName): EventDispatcher\AsyncEventListener -{ - return new EventDispatcher\AsyncEventListener($server, $regularListenerName); -} diff --git a/module/EventDispatcher/config/event_dispatcher.config.php b/module/EventDispatcher/config/event_dispatcher.config.php new file mode 100644 index 00000000..9930d9e3 --- /dev/null +++ b/module/EventDispatcher/config/event_dispatcher.config.php @@ -0,0 +1,27 @@ + [ + 'regular' => [], + 'async' => [], + ], + + 'dependencies' => [ + 'factories' => [ + Phly\EventDispatcher::class => Phly\EventDispatcherFactory::class, + Psr\ListenerProviderInterface::class => Listener\ListenerProviderFactory::class, + ], + 'aliases' => [ + Psr\EventDispatcherInterface::class => Phly\EventDispatcher::class, + ], + ], + +]; diff --git a/module/Common/config/task_runner.config.php b/module/EventDispatcher/config/task_runner.config.php similarity index 56% rename from module/Common/config/task_runner.config.php rename to module/EventDispatcher/config/task_runner.config.php index 8f0e688e..a0a23db5 100644 --- a/module/Common/config/task_runner.config.php +++ b/module/EventDispatcher/config/task_runner.config.php @@ -1,7 +1,7 @@ [ 'factories' => [ - EventDispatcher\TaskRunner::class => EventDispatcher\TaskRunnerFactory::class, + Async\TaskRunner::class => Async\TaskRunnerFactory::class, ], 'delegators' => [ HttpServer::class => [ - EventDispatcher\TaskRunnerDelegator::class, + Async\TaskRunnerDelegator::class, ], ], ], diff --git a/module/EventDispatcher/functions/functions.php b/module/EventDispatcher/functions/functions.php new file mode 100644 index 00000000..a1c93231 --- /dev/null +++ b/module/EventDispatcher/functions/functions.php @@ -0,0 +1,11 @@ + ./module/CLI/test - - ./module/Installer/test + + ./module/EventDispatcher/test