Use MercureOptions instead of raw config, where possible

This commit is contained in:
Alejandro Celaya 2023-06-06 20:25:14 +02:00
parent e72b424968
commit 8e3508f28d
4 changed files with 8 additions and 5 deletions

View File

@ -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",

View File

@ -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,
],

View File

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

View File

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