mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-08 00:03:12 +08:00
Allow individual real-time updates topics to be enabled
This commit is contained in:
@@ -85,6 +85,7 @@ enum EnvVars: string
|
||||
case MEMORY_LIMIT = 'MEMORY_LIMIT';
|
||||
case INITIAL_API_KEY = 'INITIAL_API_KEY';
|
||||
case SKIP_INITIAL_GEOLITE_DOWNLOAD = 'SKIP_INITIAL_GEOLITE_DOWNLOAD';
|
||||
case REAL_TIME_UPDATES_TOPICS = 'REAL_TIME_UPDATES_TOPICS';
|
||||
|
||||
/** @deprecated Use REDIRECT_EXTRA_PATH */
|
||||
case REDIRECT_APPEND_EXTRA_PATH = 'REDIRECT_APPEND_EXTRA_PATH';
|
||||
|
||||
39
module/Core/src/Config/Options/RealTimeUpdatesOptions.php
Normal file
39
module/Core/src/Config/Options/RealTimeUpdatesOptions.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Config\Options;
|
||||
|
||||
use Shlinkio\Shlink\Core\Config\EnvVars;
|
||||
use Shlinkio\Shlink\Core\EventDispatcher\Topic;
|
||||
|
||||
use function count;
|
||||
use function Shlinkio\Shlink\Core\ArrayUtils\contains;
|
||||
use function Shlinkio\Shlink\Core\splitByComma;
|
||||
|
||||
final readonly class RealTimeUpdatesOptions
|
||||
{
|
||||
public array $enabledTopics;
|
||||
|
||||
public function __construct(array|null $enabledTopics = null)
|
||||
{
|
||||
$this->enabledTopics = $enabledTopics ?? Topic::allTopicNames();
|
||||
}
|
||||
|
||||
public static function fromEnv(): self
|
||||
{
|
||||
$enabledTopics = splitByComma(EnvVars::REAL_TIME_UPDATES_TOPICS->loadFromEnv());
|
||||
|
||||
return new self(
|
||||
enabledTopics: count($enabledTopics) === 0
|
||||
? Topic::allTopicNames()
|
||||
// TODO Validate provided topics are in fact Topic names
|
||||
: splitByComma(EnvVars::REAL_TIME_UPDATES_TOPICS->loadFromEnv()),
|
||||
);
|
||||
}
|
||||
|
||||
public function isTopicEnabled(Topic $topic): bool
|
||||
{
|
||||
return contains($topic->name, $this->enabledTopics);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user