Defined enum with supported remote systems

This commit is contained in:
Alejandro Celaya 2022-07-28 10:25:55 +02:00
parent e36c4d397c
commit 4cf433a994
10 changed files with 33 additions and 15 deletions

View file

@ -8,5 +8,5 @@ abstract class AbstractAsyncListener
{ {
abstract protected function isEnabled(): bool; abstract protected function isEnabled(): bool;
abstract protected function getRemoteSystemName(): string; abstract protected function getRemoteSystem(): RemoteSystem;
} }

View file

@ -30,7 +30,7 @@ abstract class AbstractNotifyNewShortUrlListener extends AbstractAsyncListener
$shortUrlId = $shortUrlCreated->shortUrlId; $shortUrlId = $shortUrlCreated->shortUrlId;
$shortUrl = $this->em->find(ShortUrl::class, $shortUrlId); $shortUrl = $this->em->find(ShortUrl::class, $shortUrlId);
$name = $this->getRemoteSystemName(); $name = $this->getRemoteSystem()->value;
if ($shortUrl === null) { if ($shortUrl === null) {
$this->logger->warning( $this->logger->warning(

View file

@ -33,7 +33,7 @@ abstract class AbstractNotifyVisitListener extends AbstractAsyncListener
$visitId = $visitLocated->visitId; $visitId = $visitLocated->visitId;
$visit = $this->em->find(Visit::class, $visitId); $visit = $this->em->find(Visit::class, $visitId);
$name = $this->getRemoteSystemName(); $name = $this->getRemoteSystem()->value;
if ($visit === null) { if ($visit === null) {
$this->logger->warning( $this->logger->warning(

View file

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Core\EventDispatcher\Async;
enum RemoteSystem: string
{
case MERCURE = 'Mercure';
case RABBIT_MQ = 'RabbitMQ';
case REDIS_PUB_SUB = 'Redis pub/sub';
}

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\EventDispatcher\Mercure; namespace Shlinkio\Shlink\Core\EventDispatcher\Mercure;
use Shlinkio\Shlink\Core\EventDispatcher\Async\AbstractNotifyNewShortUrlListener; use Shlinkio\Shlink\Core\EventDispatcher\Async\AbstractNotifyNewShortUrlListener;
use Shlinkio\Shlink\Core\EventDispatcher\Async\RemoteSystem;
class NotifyNewShortUrlToMercure extends AbstractNotifyNewShortUrlListener class NotifyNewShortUrlToMercure extends AbstractNotifyNewShortUrlListener
{ {
@ -13,8 +14,8 @@ class NotifyNewShortUrlToMercure extends AbstractNotifyNewShortUrlListener
return true; return true;
} }
protected function getRemoteSystemName(): string protected function getRemoteSystem(): RemoteSystem
{ {
return 'Mercure'; return RemoteSystem::MERCURE;
} }
} }

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\EventDispatcher\Mercure; namespace Shlinkio\Shlink\Core\EventDispatcher\Mercure;
use Shlinkio\Shlink\Core\EventDispatcher\Async\AbstractNotifyVisitListener; use Shlinkio\Shlink\Core\EventDispatcher\Async\AbstractNotifyVisitListener;
use Shlinkio\Shlink\Core\EventDispatcher\Async\RemoteSystem;
class NotifyVisitToMercure extends AbstractNotifyVisitListener class NotifyVisitToMercure extends AbstractNotifyVisitListener
{ {
@ -13,8 +14,8 @@ class NotifyVisitToMercure extends AbstractNotifyVisitListener
return true; return true;
} }
protected function getRemoteSystemName(): string protected function getRemoteSystem(): RemoteSystem
{ {
return 'Mercure'; return RemoteSystem::MERCURE;
} }
} }

View file

@ -8,6 +8,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface; use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface;
use Shlinkio\Shlink\Core\EventDispatcher\Async\AbstractNotifyNewShortUrlListener; use Shlinkio\Shlink\Core\EventDispatcher\Async\AbstractNotifyNewShortUrlListener;
use Shlinkio\Shlink\Core\EventDispatcher\Async\RemoteSystem;
use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGeneratorInterface; use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGeneratorInterface;
use Shlinkio\Shlink\Core\Options\RabbitMqOptions; use Shlinkio\Shlink\Core\Options\RabbitMqOptions;
@ -28,8 +29,8 @@ class NotifyNewShortUrlToRabbitMq extends AbstractNotifyNewShortUrlListener
return $this->options->isEnabled(); return $this->options->isEnabled();
} }
protected function getRemoteSystemName(): string protected function getRemoteSystem(): RemoteSystem
{ {
return 'RabbitMQ'; return RemoteSystem::RABBIT_MQ;
} }
} }

View file

@ -11,6 +11,7 @@ use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface;
use Shlinkio\Shlink\Common\UpdatePublishing\Update; use Shlinkio\Shlink\Common\UpdatePublishing\Update;
use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Entity\Visit;
use Shlinkio\Shlink\Core\EventDispatcher\Async\AbstractNotifyVisitListener; use Shlinkio\Shlink\Core\EventDispatcher\Async\AbstractNotifyVisitListener;
use Shlinkio\Shlink\Core\EventDispatcher\Async\RemoteSystem;
use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGeneratorInterface; use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGeneratorInterface;
use Shlinkio\Shlink\Core\EventDispatcher\Topic; use Shlinkio\Shlink\Core\EventDispatcher\Topic;
use Shlinkio\Shlink\Core\Options\RabbitMqOptions; use Shlinkio\Shlink\Core\Options\RabbitMqOptions;
@ -62,8 +63,8 @@ class NotifyVisitToRabbitMq extends AbstractNotifyVisitListener
return $this->options->isEnabled(); return $this->options->isEnabled();
} }
protected function getRemoteSystemName(): string protected function getRemoteSystem(): RemoteSystem
{ {
return 'RabbitMQ'; return RemoteSystem::RABBIT_MQ;
} }
} }

View file

@ -8,6 +8,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface; use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface;
use Shlinkio\Shlink\Core\EventDispatcher\Async\AbstractNotifyNewShortUrlListener; use Shlinkio\Shlink\Core\EventDispatcher\Async\AbstractNotifyNewShortUrlListener;
use Shlinkio\Shlink\Core\EventDispatcher\Async\RemoteSystem;
use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGeneratorInterface; use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGeneratorInterface;
class NotifyNewShortUrlToRedis extends AbstractNotifyNewShortUrlListener class NotifyNewShortUrlToRedis extends AbstractNotifyNewShortUrlListener
@ -27,8 +28,8 @@ class NotifyNewShortUrlToRedis extends AbstractNotifyNewShortUrlListener
return $this->enabled; return $this->enabled;
} }
protected function getRemoteSystemName(): string protected function getRemoteSystem(): RemoteSystem
{ {
return 'Redis pub/sub'; return RemoteSystem::REDIS_PUB_SUB;
} }
} }

View file

@ -8,6 +8,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface; use Shlinkio\Shlink\Common\UpdatePublishing\PublishingHelperInterface;
use Shlinkio\Shlink\Core\EventDispatcher\Async\AbstractNotifyVisitListener; use Shlinkio\Shlink\Core\EventDispatcher\Async\AbstractNotifyVisitListener;
use Shlinkio\Shlink\Core\EventDispatcher\Async\RemoteSystem;
use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGeneratorInterface; use Shlinkio\Shlink\Core\EventDispatcher\PublishingUpdatesGeneratorInterface;
class NotifyVisitToRedis extends AbstractNotifyVisitListener class NotifyVisitToRedis extends AbstractNotifyVisitListener
@ -27,8 +28,8 @@ class NotifyVisitToRedis extends AbstractNotifyVisitListener
return $this->enabled; return $this->enabled;
} }
protected function getRemoteSystemName(): string protected function getRemoteSystem(): RemoteSystem
{ {
return 'Redis pub/sub'; return RemoteSystem::REDIS_PUB_SUB;
} }
} }