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

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