From 2e8f5202d03b5b6754ff5678ffe48c3b978196ee Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 17 Jan 2021 11:42:35 +0100 Subject: [PATCH] Moved event objects to a sub-namespace inside Core\EventDispatcher --- .../Core/config/event_dispatcher.config.php | 4 +-- .../Event/AbstractVisitEvent.php | 27 +++++++++++++++++++ .../EventDispatcher/Event/ShortUrlVisited.php | 19 +++---------- .../EventDispatcher/Event/VisitLocated.php | 22 ++------------- .../EventDispatcher/LocateShortUrlVisit.php | 2 ++ .../EventDispatcher/NotifyVisitToMercure.php | 1 + .../EventDispatcher/NotifyVisitToWebHooks.php | 1 + module/Core/src/Service/VisitsTracker.php | 2 +- .../LocateShortUrlVisitTest.php | 4 +-- .../NotifyVisitToMercureTest.php | 2 +- .../NotifyVisitToWebHooksTest.php | 2 +- .../Core/test/Service/VisitsTrackerTest.php | 2 +- 12 files changed, 44 insertions(+), 44 deletions(-) create mode 100644 module/Core/src/EventDispatcher/Event/AbstractVisitEvent.php diff --git a/module/Core/config/event_dispatcher.config.php b/module/Core/config/event_dispatcher.config.php index c72e2d7a..83390fdd 100644 --- a/module/Core/config/event_dispatcher.config.php +++ b/module/Core/config/event_dispatcher.config.php @@ -14,13 +14,13 @@ return [ 'events' => [ 'regular' => [ - EventDispatcher\VisitLocated::class => [ + EventDispatcher\Event\VisitLocated::class => [ EventDispatcher\NotifyVisitToMercure::class, EventDispatcher\NotifyVisitToWebHooks::class, ], ], 'async' => [ - EventDispatcher\ShortUrlVisited::class => [ + EventDispatcher\Event\ShortUrlVisited::class => [ EventDispatcher\LocateShortUrlVisit::class, ], ], diff --git a/module/Core/src/EventDispatcher/Event/AbstractVisitEvent.php b/module/Core/src/EventDispatcher/Event/AbstractVisitEvent.php new file mode 100644 index 00000000..09869cb2 --- /dev/null +++ b/module/Core/src/EventDispatcher/Event/AbstractVisitEvent.php @@ -0,0 +1,27 @@ +visitId = $visitId; + } + + public function visitId(): string + { + return $this->visitId; + } + + public function jsonSerialize(): array + { + return ['visitId' => $this->visitId]; + } +} diff --git a/module/Core/src/EventDispatcher/Event/ShortUrlVisited.php b/module/Core/src/EventDispatcher/Event/ShortUrlVisited.php index 2cac3dbc..f177721f 100644 --- a/module/Core/src/EventDispatcher/Event/ShortUrlVisited.php +++ b/module/Core/src/EventDispatcher/Event/ShortUrlVisited.php @@ -2,33 +2,20 @@ declare(strict_types=1); -namespace Shlinkio\Shlink\Core\EventDispatcher; +namespace Shlinkio\Shlink\Core\EventDispatcher\Event; -use JsonSerializable; - -final class ShortUrlVisited implements JsonSerializable +final class ShortUrlVisited extends AbstractVisitEvent { - private string $visitId; private ?string $originalIpAddress; public function __construct(string $visitId, ?string $originalIpAddress = null) { - $this->visitId = $visitId; + parent::__construct($visitId); $this->originalIpAddress = $originalIpAddress; } - public function visitId(): string - { - return $this->visitId; - } - public function originalIpAddress(): ?string { return $this->originalIpAddress; } - - public function jsonSerialize(): array - { - return ['visitId' => $this->visitId, 'originalIpAddress' => '']; - } } diff --git a/module/Core/src/EventDispatcher/Event/VisitLocated.php b/module/Core/src/EventDispatcher/Event/VisitLocated.php index 0e1c1176..99b7a05e 100644 --- a/module/Core/src/EventDispatcher/Event/VisitLocated.php +++ b/module/Core/src/EventDispatcher/Event/VisitLocated.php @@ -2,26 +2,8 @@ declare(strict_types=1); -namespace Shlinkio\Shlink\Core\EventDispatcher; +namespace Shlinkio\Shlink\Core\EventDispatcher\Event; -use JsonSerializable; - -final class VisitLocated implements JsonSerializable +final class VisitLocated extends AbstractVisitEvent { - private string $visitId; - - public function __construct(string $visitId) - { - $this->visitId = $visitId; - } - - public function visitId(): string - { - return $this->visitId; - } - - public function jsonSerialize(): array - { - return ['visitId' => $this->visitId]; - } } diff --git a/module/Core/src/EventDispatcher/LocateShortUrlVisit.php b/module/Core/src/EventDispatcher/LocateShortUrlVisit.php index 6abbe02b..8b193578 100644 --- a/module/Core/src/EventDispatcher/LocateShortUrlVisit.php +++ b/module/Core/src/EventDispatcher/LocateShortUrlVisit.php @@ -11,6 +11,8 @@ use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException; use Shlinkio\Shlink\CLI\Util\GeolocationDbUpdaterInterface; use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Entity\VisitLocation; +use Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlVisited; +use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated; use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException; use Shlinkio\Shlink\IpGeolocation\Model\Location; use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface; diff --git a/module/Core/src/EventDispatcher/NotifyVisitToMercure.php b/module/Core/src/EventDispatcher/NotifyVisitToMercure.php index af6dd33f..33aab7af 100644 --- a/module/Core/src/EventDispatcher/NotifyVisitToMercure.php +++ b/module/Core/src/EventDispatcher/NotifyVisitToMercure.php @@ -7,6 +7,7 @@ namespace Shlinkio\Shlink\Core\EventDispatcher; use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Entity\Visit; +use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated; use Shlinkio\Shlink\Core\Mercure\MercureUpdatesGeneratorInterface; use Symfony\Component\Mercure\PublisherInterface; use Throwable; diff --git a/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php b/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php index b3923b86..2add5698 100644 --- a/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php +++ b/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php @@ -13,6 +13,7 @@ use GuzzleHttp\Promise\PromiseInterface; use GuzzleHttp\RequestOptions; use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Entity\Visit; +use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated; use Shlinkio\Shlink\Core\Options\AppOptions; use Shlinkio\Shlink\Core\Transformer\ShortUrlDataTransformer; use Throwable; diff --git a/module/Core/src/Service/VisitsTracker.php b/module/Core/src/Service/VisitsTracker.php index fc35499f..46d4bd6b 100644 --- a/module/Core/src/Service/VisitsTracker.php +++ b/module/Core/src/Service/VisitsTracker.php @@ -10,7 +10,7 @@ use Psr\EventDispatcher\EventDispatcherInterface; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Entity\Visit; -use Shlinkio\Shlink\Core\EventDispatcher\ShortUrlVisited; +use Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlVisited; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; use Shlinkio\Shlink\Core\Exception\TagNotFoundException; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; diff --git a/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php b/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php index ab12a349..8c9119a5 100644 --- a/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php +++ b/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php @@ -17,9 +17,9 @@ use Shlinkio\Shlink\Common\Util\IpAddress; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Entity\VisitLocation; +use Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlVisited; +use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated; use Shlinkio\Shlink\Core\EventDispatcher\LocateShortUrlVisit; -use Shlinkio\Shlink\Core\EventDispatcher\ShortUrlVisited; -use Shlinkio\Shlink\Core\EventDispatcher\VisitLocated; use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException; use Shlinkio\Shlink\IpGeolocation\Model\Location; diff --git a/module/Core/test/EventDispatcher/NotifyVisitToMercureTest.php b/module/Core/test/EventDispatcher/NotifyVisitToMercureTest.php index 90891db3..b8e71297 100644 --- a/module/Core/test/EventDispatcher/NotifyVisitToMercureTest.php +++ b/module/Core/test/EventDispatcher/NotifyVisitToMercureTest.php @@ -13,8 +13,8 @@ use Psr\Log\LoggerInterface; 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\VisitLocated; use Shlinkio\Shlink\Core\Mercure\MercureUpdatesGeneratorInterface; use Shlinkio\Shlink\Core\Model\Visitor; use Symfony\Component\Mercure\PublisherInterface; diff --git a/module/Core/test/EventDispatcher/NotifyVisitToWebHooksTest.php b/module/Core/test/EventDispatcher/NotifyVisitToWebHooksTest.php index 8319f448..e7021e18 100644 --- a/module/Core/test/EventDispatcher/NotifyVisitToWebHooksTest.php +++ b/module/Core/test/EventDispatcher/NotifyVisitToWebHooksTest.php @@ -19,8 +19,8 @@ use Prophecy\Prophecy\ObjectProphecy; use Psr\Log\LoggerInterface; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\Visit; +use Shlinkio\Shlink\Core\EventDispatcher\Event\VisitLocated; use Shlinkio\Shlink\Core\EventDispatcher\NotifyVisitToWebHooks; -use Shlinkio\Shlink\Core\EventDispatcher\VisitLocated; use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\Core\Options\AppOptions; diff --git a/module/Core/test/Service/VisitsTrackerTest.php b/module/Core/test/Service/VisitsTrackerTest.php index ef894aaf..17135f57 100644 --- a/module/Core/test/Service/VisitsTrackerTest.php +++ b/module/Core/test/Service/VisitsTrackerTest.php @@ -15,7 +15,7 @@ use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Entity\Visit; -use Shlinkio\Shlink\Core\EventDispatcher\ShortUrlVisited; +use Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlVisited; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; use Shlinkio\Shlink\Core\Exception\TagNotFoundException; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;