Merge pull request #1807 from acelaya-forks/feature/mercure-options

Use MercureOptions instead of raw config, where possible
This commit is contained in:
Alejandro Celaya 2023-06-08 19:00:43 +02:00 committed by GitHub
commit a21fcd72ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 5 deletions

View File

@ -45,7 +45,7 @@
"php-middleware/request-id": "^4.1", "php-middleware/request-id": "^4.1",
"pugx/shortid-php": "^1.1", "pugx/shortid-php": "^1.1",
"ramsey/uuid": "^4.7", "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-config": "dev-main#245bbdd as 2.5",
"shlinkio/shlink-event-dispatcher": "dev-main#bd3a62b as 3.1", "shlinkio/shlink-event-dispatcher": "dev-main#bd3a62b as 3.1",
"shlinkio/shlink-importer": "^5.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\CLI\GeoLite\GeolocationDbUpdater;
use Shlinkio\Shlink\Common\Cache\RedisPublishingHelper; use Shlinkio\Shlink\Common\Cache\RedisPublishingHelper;
use Shlinkio\Shlink\Common\Mercure\MercureHubPublishingHelper; use Shlinkio\Shlink\Common\Mercure\MercureHubPublishingHelper;
use Shlinkio\Shlink\Common\Mercure\MercureOptions;
use Shlinkio\Shlink\Common\RabbitMq\RabbitMqPublishingHelper; use Shlinkio\Shlink\Common\RabbitMq\RabbitMqPublishingHelper;
use Shlinkio\Shlink\Core\Visit\Geolocation\VisitLocator; use Shlinkio\Shlink\Core\Visit\Geolocation\VisitLocator;
use Shlinkio\Shlink\Core\Visit\Geolocation\VisitToLocationHelper; use Shlinkio\Shlink\Core\Visit\Geolocation\VisitToLocationHelper;
@ -159,7 +160,7 @@ return [
EventDispatcher\Helper\EnabledListenerChecker::class => [ EventDispatcher\Helper\EnabledListenerChecker::class => [
Options\RabbitMqOptions::class, Options\RabbitMqOptions::class,
'config.redis.pub_sub_enabled', 'config.redis.pub_sub_enabled',
'config.mercure.public_hub_url', MercureOptions::class,
Options\WebhookOptions::class, Options\WebhookOptions::class,
GeoLite2Options::class, GeoLite2Options::class,
], ],

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Core\EventDispatcher\Helper; namespace Shlinkio\Shlink\Core\EventDispatcher\Helper;
use Shlinkio\Shlink\Common\Mercure\MercureOptions;
use Shlinkio\Shlink\Core\EventDispatcher; use Shlinkio\Shlink\Core\EventDispatcher;
use Shlinkio\Shlink\Core\Options\RabbitMqOptions; use Shlinkio\Shlink\Core\Options\RabbitMqOptions;
use Shlinkio\Shlink\Core\Options\WebhookOptions; use Shlinkio\Shlink\Core\Options\WebhookOptions;
@ -15,7 +16,7 @@ class EnabledListenerChecker implements EnabledListenerCheckerInterface
public function __construct( public function __construct(
private readonly RabbitMqOptions $rabbitMqOptions, private readonly RabbitMqOptions $rabbitMqOptions,
private readonly bool $redisPubSubEnabled, private readonly bool $redisPubSubEnabled,
private readonly ?string $publicMercureHubUrl, private readonly MercureOptions $mercureOptions,
private readonly WebhookOptions $webhookOptions, private readonly WebhookOptions $webhookOptions,
private readonly GeoLite2Options $geoLiteOptions, private readonly GeoLite2Options $geoLiteOptions,
) { ) {
@ -33,7 +34,7 @@ class EnabledListenerChecker implements EnabledListenerCheckerInterface
EventDispatcher\RedisPubSub\NotifyVisitToRedis::class, EventDispatcher\RedisPubSub\NotifyVisitToRedis::class,
EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis::class => $this->redisPubSubEnabled, EventDispatcher\RedisPubSub\NotifyNewShortUrlToRedis::class => $this->redisPubSubEnabled,
EventDispatcher\Mercure\NotifyVisitToMercure::class, 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\NotifyVisitToWebHooks::class => $this->webhookOptions->hasWebhooks(),
EventDispatcher\UpdateGeoLiteDb::class => $this->geoLiteOptions->hasLicenseKey(), EventDispatcher\UpdateGeoLiteDb::class => $this->geoLiteOptions->hasLicenseKey(),
default => false, // Any unknown async listener should not be enabled by default 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\DataProvider;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Common\Mercure\MercureOptions;
use Shlinkio\Shlink\Core\EventDispatcher\Helper\EnabledListenerChecker; use Shlinkio\Shlink\Core\EventDispatcher\Helper\EnabledListenerChecker;
use Shlinkio\Shlink\Core\EventDispatcher\Mercure\NotifyNewShortUrlToMercure; use Shlinkio\Shlink\Core\EventDispatcher\Mercure\NotifyNewShortUrlToMercure;
use Shlinkio\Shlink\Core\EventDispatcher\Mercure\NotifyVisitToMercure; use Shlinkio\Shlink\Core\EventDispatcher\Mercure\NotifyVisitToMercure;
@ -152,7 +153,7 @@ class EnabledListenerCheckerTest extends TestCase
return new EnabledListenerChecker( return new EnabledListenerChecker(
new RabbitMqOptions(enabled: $rabbitMqEnabled), new RabbitMqOptions(enabled: $rabbitMqEnabled),
$redisPubSubEnabled, $redisPubSubEnabled,
$mercureEnabled ? 'the-url' : null, new MercureOptions(publicHubUrl: $mercureEnabled ? 'the-url' : null),
new WebhookOptions(['webhooks' => $webhooksEnabled ? ['foo', 'bar'] : []]), new WebhookOptions(['webhooks' => $webhooksEnabled ? ['foo', 'bar'] : []]),
new GeoLite2Options(licenseKey: $geoLiteEnabled ? 'the-key' : null), new GeoLite2Options(licenseKey: $geoLiteEnabled ? 'the-key' : null),
); );