From 8e3508f28d4d0f4e19f578f30abd2f06243f1e9a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 6 Jun 2023 20:25:14 +0200 Subject: [PATCH] Use MercureOptions instead of raw config, where possible --- composer.json | 2 +- module/Core/config/event_dispatcher.config.php | 3 ++- .../src/EventDispatcher/Helper/EnabledListenerChecker.php | 5 +++-- .../EventDispatcher/Helper/EnabledListenerCheckerTest.php | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 99a71e50..6fab70c4 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "php-middleware/request-id": "^4.1", "pugx/shortid-php": "^1.1", "ramsey/uuid": "^4.7", - "shlinkio/shlink-common": "^5.5", + "shlinkio/shlink-common": "dev-main#b38c1ad as 5.6", "shlinkio/shlink-config": "dev-main#245bbdd as 2.5", "shlinkio/shlink-event-dispatcher": "dev-main#bd3a62b as 3.1", "shlinkio/shlink-importer": "^5.1", diff --git a/module/Core/config/event_dispatcher.config.php b/module/Core/config/event_dispatcher.config.php index a7867240..ac8626e8 100644 --- a/module/Core/config/event_dispatcher.config.php +++ b/module/Core/config/event_dispatcher.config.php @@ -9,6 +9,7 @@ use Psr\EventDispatcher\EventDispatcherInterface; use Shlinkio\Shlink\CLI\GeoLite\GeolocationDbUpdater; use Shlinkio\Shlink\Common\Cache\RedisPublishingHelper; use Shlinkio\Shlink\Common\Mercure\MercureHubPublishingHelper; +use Shlinkio\Shlink\Common\Mercure\MercureOptions; use Shlinkio\Shlink\Common\RabbitMq\RabbitMqPublishingHelper; use Shlinkio\Shlink\Core\Visit\Geolocation\VisitLocator; use Shlinkio\Shlink\Core\Visit\Geolocation\VisitToLocationHelper; @@ -159,7 +160,7 @@ return [ EventDispatcher\Helper\EnabledListenerChecker::class => [ Options\RabbitMqOptions::class, 'config.redis.pub_sub_enabled', - 'config.mercure.public_hub_url', + MercureOptions::class, Options\WebhookOptions::class, GeoLite2Options::class, ], diff --git a/module/Core/src/EventDispatcher/Helper/EnabledListenerChecker.php b/module/Core/src/EventDispatcher/Helper/EnabledListenerChecker.php index d7e231a2..97c0ca5d 100644 --- a/module/Core/src/EventDispatcher/Helper/EnabledListenerChecker.php +++ b/module/Core/src/EventDispatcher/Helper/EnabledListenerChecker.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\EventDispatcher\Helper; +use Shlinkio\Shlink\Common\Mercure\MercureOptions; use Shlinkio\Shlink\Core\EventDispatcher; use Shlinkio\Shlink\Core\Options\RabbitMqOptions; use Shlinkio\Shlink\Core\Options\WebhookOptions; @@ -15,7 +16,7 @@ class EnabledListenerChecker implements EnabledListenerCheckerInterface public function __construct( private readonly RabbitMqOptions $rabbitMqOptions, private readonly bool $redisPubSubEnabled, - private readonly ?string $publicMercureHubUrl, + private readonly MercureOptions $mercureOptions, private readonly WebhookOptions $webhookOptions, private readonly GeoLite2Options $geoLiteOptions, ) { @@ -33,7 +34,7 @@ class EnabledListenerChecker implements EnabledListenerCheckerInterface EventDispatcher\RedisPubSub\NotifyVisitToRedis::class, EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis::class => $this->redisPubSubEnabled, EventDispatcher\Mercure\NotifyVisitToMercure::class, - EventDispatcher\Mercure\NotifyNewShortUrlToMercure::class => $this->publicMercureHubUrl !== null, + EventDispatcher\Mercure\NotifyNewShortUrlToMercure::class => $this->mercureOptions->isEnabled(), EventDispatcher\NotifyVisitToWebHooks::class => $this->webhookOptions->hasWebhooks(), EventDispatcher\UpdateGeoLiteDb::class => $this->geoLiteOptions->hasLicenseKey(), default => false, // Any unknown async listener should not be enabled by default diff --git a/module/Core/test/EventDispatcher/Helper/EnabledListenerCheckerTest.php b/module/Core/test/EventDispatcher/Helper/EnabledListenerCheckerTest.php index a98c1e67..de5017bd 100644 --- a/module/Core/test/EventDispatcher/Helper/EnabledListenerCheckerTest.php +++ b/module/Core/test/EventDispatcher/Helper/EnabledListenerCheckerTest.php @@ -7,6 +7,7 @@ namespace ShlinkioTest\Shlink\Core\EventDispatcher\Helper; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; +use Shlinkio\Shlink\Common\Mercure\MercureOptions; use Shlinkio\Shlink\Core\EventDispatcher\Helper\EnabledListenerChecker; use Shlinkio\Shlink\Core\EventDispatcher\Mercure\NotifyNewShortUrlToMercure; use Shlinkio\Shlink\Core\EventDispatcher\Mercure\NotifyVisitToMercure; @@ -152,7 +153,7 @@ class EnabledListenerCheckerTest extends TestCase return new EnabledListenerChecker( new RabbitMqOptions(enabled: $rabbitMqEnabled), $redisPubSubEnabled, - $mercureEnabled ? 'the-url' : null, + new MercureOptions(publicHubUrl: $mercureEnabled ? 'the-url' : null), new WebhookOptions(['webhooks' => $webhooksEnabled ? ['foo', 'bar'] : []]), new GeoLite2Options(licenseKey: $geoLiteEnabled ? 'the-key' : null), );