Moved Mercure and RabbitMq event listeners to their own subnamespaces

This commit is contained in:
Alejandro Celaya 2022-07-21 20:07:28 +02:00
parent 1aa9ae680e
commit f832c56adb
8 changed files with 70 additions and 15 deletions

View file

@ -22,11 +22,15 @@ return [
],
'async' => [
EventDispatcher\Event\VisitLocated::class => [
EventDispatcher\NotifyVisitToMercure::class,
EventDispatcher\NotifyVisitToRabbitMq::class,
EventDispatcher\Mercure\NotifyVisitToMercure::class,
EventDispatcher\RabbitMq\NotifyVisitToRabbitMq::class,
EventDispatcher\NotifyVisitToWebHooks::class,
EventDispatcher\UpdateGeoLiteDb::class,
],
// EventDispatcher\Event\ShortUrlCreated::class => [
// EventDispatcher\Mercure\NotifyNewShortUrlToMercure::class,
// EventDispatcher\RabbitMq\NotifyNewShortUrlToRabbitMq::class,
// ],
],
],
@ -34,16 +38,16 @@ return [
'factories' => [
EventDispatcher\LocateVisit::class => ConfigAbstractFactory::class,
EventDispatcher\NotifyVisitToWebHooks::class => ConfigAbstractFactory::class,
EventDispatcher\NotifyVisitToMercure::class => ConfigAbstractFactory::class,
EventDispatcher\NotifyVisitToRabbitMq::class => ConfigAbstractFactory::class,
EventDispatcher\Mercure\NotifyVisitToMercure::class => ConfigAbstractFactory::class,
EventDispatcher\RabbitMq\NotifyVisitToRabbitMq::class => ConfigAbstractFactory::class,
EventDispatcher\UpdateGeoLiteDb::class => ConfigAbstractFactory::class,
],
'delegators' => [
EventDispatcher\NotifyVisitToMercure::class => [
EventDispatcher\Mercure\NotifyVisitToMercure::class => [
EventDispatcher\CloseDbConnectionEventListenerDelegator::class,
],
EventDispatcher\NotifyVisitToRabbitMq::class => [
EventDispatcher\RabbitMq\NotifyVisitToRabbitMq::class => [
EventDispatcher\CloseDbConnectionEventListenerDelegator::class,
],
EventDispatcher\NotifyVisitToWebHooks::class => [
@ -68,13 +72,13 @@ return [
ShortUrl\Transformer\ShortUrlDataTransformer::class,
Options\AppOptions::class,
],
EventDispatcher\NotifyVisitToMercure::class => [
EventDispatcher\Mercure\NotifyVisitToMercure::class => [
Hub::class,
Mercure\MercureUpdatesGenerator::class,
'em',
'Logger_Shlink',
],
EventDispatcher\NotifyVisitToRabbitMq::class => [
EventDispatcher\RabbitMq\NotifyVisitToRabbitMq::class => [
AMQPStreamConnection::class,
'em',
'Logger_Shlink',

View file

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Core\EventDispatcher\Event;
use JsonSerializable;
final class ShortUrlCreated implements JsonSerializable
{
public function __construct(public readonly string $shortUrlId)
{
}
public function jsonSerialize(): array
{
return [
'shortUrlId' => $this->shortUrlId,
];
}
}

View file

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Core\EventDispatcher\Mercure;
use Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlCreated;
class NotifyNewShortUrlToMercure
{
public function __invoke(ShortUrlCreated $shortUrlCreated)
{
// TODO: Implement __invoke() method.
}
}

View file

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Shlinkio\Shlink\Core\EventDispatcher;
namespace Shlinkio\Shlink\Core\EventDispatcher\Mercure;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;

View file

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Core\EventDispatcher\RabbitMq;
use Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlCreated;
class NotifyNewShortUrlToRabbitMq
{
public function __invoke(ShortUrlCreated $shortUrlCreated)
{
// TODO: Implement __invoke() method.
}
}

View file

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Shlinkio\Shlink\Core\EventDispatcher;
namespace Shlinkio\Shlink\Core\EventDispatcher\RabbitMq;
use Doctrine\ORM\EntityManagerInterface;
use PhpAmqpLib\Connection\AMQPStreamConnection;

View file

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\EventDispatcher;
namespace ShlinkioTest\Shlink\Core\EventDispatcher\Mercure;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
@ -14,7 +14,7 @@ use RuntimeException;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Entity\Visit;
use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated;
use Shlinkio\Shlink\Core\EventDispatcher\NotifyVisitToMercure;
use Shlinkio\Shlink\Core\EventDispatcher\Mercure\NotifyVisitToMercure;
use Shlinkio\Shlink\Core\Mercure\MercureUpdatesGeneratorInterface;
use Shlinkio\Shlink\Core\Model\Visitor;
use Shlinkio\Shlink\Core\Visit\Model\VisitType;

View file

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\EventDispatcher;
namespace ShlinkioTest\Shlink\Core\EventDispatcher\RabbitMq;
use Doctrine\ORM\EntityManagerInterface;
use DomainException;
@ -18,7 +18,7 @@ use RuntimeException;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Entity\Visit;
use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated;
use Shlinkio\Shlink\Core\EventDispatcher\NotifyVisitToRabbitMq;
use Shlinkio\Shlink\Core\EventDispatcher\RabbitMq\NotifyVisitToRabbitMq;
use Shlinkio\Shlink\Core\Model\ShortUrlMeta;
use Shlinkio\Shlink\Core\Model\Visitor;
use Shlinkio\Shlink\Core\Visit\Transformer\OrphanVisitDataTransformer;
@ -61,7 +61,7 @@ class NotifyVisitToRabbitMqTest extends TestCase
/** @test */
public function doesNothingWhenTheFeatureIsNotEnabled(): void
{
$listener = new NotifyVisitToRabbitMq(
$listener = new \Shlinkio\Shlink\Core\EventDispatcher\RabbitMq\NotifyVisitToRabbitMq(
$this->connection->reveal(),
$this->em->reveal(),
$this->logger->reveal(),