Moved all event-dispatching stuff to its own module

This commit is contained in:
Alejandro Celaya 2019-07-19 19:54:39 +02:00
parent bccc177414
commit d086131630
16 changed files with 77 additions and 46 deletions

View File

@ -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": {

View File

@ -1,20 +0,0 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink;
use Phly\EventDispatcher as Phly;
use Psr\EventDispatcher as Psr;
return [
'dependencies' => [
'factories' => [
Psr\ListenerProviderInterface::class => Common\EventDispatcher\ListenerProviderFactory::class,
],
'aliases' => [
Psr\EventDispatcherInterface::class => Phly\EventDispatcher::class,
],
],
];

View File

@ -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'

View File

@ -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);
}

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\EventDispatcher;
use Phly\EventDispatcher as Phly;
use Psr\EventDispatcher as Psr;
use Shlinkio\Shlink\Common;
return [
'events' => [
'regular' => [],
'async' => [],
],
'dependencies' => [
'factories' => [
Phly\EventDispatcher::class => Phly\EventDispatcherFactory::class,
Psr\ListenerProviderInterface::class => Listener\ListenerProviderFactory::class,
],
'aliases' => [
Psr\EventDispatcherInterface::class => Phly\EventDispatcher::class,
],
],
];

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Common;
namespace Shlinkio\Shlink\EventDispatcher;
use Swoole\Http\Server as HttpServer;
@ -9,11 +9,11 @@ return [
'dependencies' => [
'factories' => [
EventDispatcher\TaskRunner::class => EventDispatcher\TaskRunnerFactory::class,
Async\TaskRunner::class => Async\TaskRunnerFactory::class,
],
'delegators' => [
HttpServer::class => [
EventDispatcher\TaskRunnerDelegator::class,
Async\TaskRunnerDelegator::class,
],
],
],

View File

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\EventDispatcher;
use Swoole\Http\Server as HttpServer;
function asyncListener(HttpServer $server, string $regularListenerName): Listener\AsyncEventListener
{
return new Listener\AsyncEventListener($server, $regularListenerName);
}

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Common\EventDispatcher;
namespace Shlinkio\Shlink\EventDispatcher\Async;
use Psr\Container\ContainerInterface;

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Common\EventDispatcher;
namespace Shlinkio\Shlink\EventDispatcher\Async;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Common\EventDispatcher;
namespace Shlinkio\Shlink\EventDispatcher\Async;
use Interop\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Common\EventDispatcher;
namespace Shlinkio\Shlink\EventDispatcher\Async;
use Interop\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\EventDispatcher;
use Zend\Config\Factory;
use Zend\Stdlib\Glob;
class ConfigProvider
{
public function __invoke()
{
return Factory::fromFiles(Glob::glob(__DIR__ . '/../config/{,*.}config.php', Glob::GLOB_BRACE));
}
}

View File

@ -1,8 +1,9 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Common\EventDispatcher;
namespace Shlinkio\Shlink\EventDispatcher\Listener;
use Shlinkio\Shlink\EventDispatcher\Async\Task;
use Swoole\Http\Server as HttpServer;
class AsyncEventListener

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Common\EventDispatcher;
namespace Shlinkio\Shlink\EventDispatcher\Listener;
use Interop\Container\ContainerInterface;
use Phly\EventDispatcher\ListenerProvider\AttachableListenerProvider;
@ -9,7 +9,7 @@ use Swoole\Http\Server as HttpServer;
use Zend\ServiceManager\Factory\FactoryInterface;
use function Phly\EventDispatcher\lazyListener;
use function Shlinkio\Shlink\Common\asyncListener;
use function Shlinkio\Shlink\EventDispatcher\asyncListener;
class ListenerProviderFactory implements FactoryInterface
{

View File

@ -1,13 +1,13 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Common\EventDispatcher;
namespace ShlinkioTest\Shlink\EventDispatcher\Listener;
use Interop\Container\ContainerInterface;
use Phly\EventDispatcher\ListenerProvider\AttachableListenerProvider;
use PHPUnit\Framework\TestCase;
use ReflectionObject;
use Shlinkio\Shlink\Common\EventDispatcher\ListenerProviderFactory;
use Shlinkio\Shlink\EventDispatcher\Listener\ListenerProviderFactory;
use function Phly\EventDispatcher\lazyListener;

View File

@ -18,8 +18,8 @@
<testsuite name="CLI">
<directory>./module/CLI/test</directory>
</testsuite>
<testsuite name="Installer">
<directory>./module/Installer/test</directory>
<testsuite name="EventDispatcher">
<directory>./module/EventDispatcher/test</directory>
</testsuite>
</testsuites>