Read config, handle lastEventId in topicmanager

This commit is contained in:
2024-03-11 22:12:01 +01:00
parent 8cbd12ee61
commit 99b5710c59
8 changed files with 71 additions and 13 deletions

View File

@ -12,6 +12,8 @@ class Configuration
private bool $allowAnonymousSubscribe = false;
private array $listeners = [];
public static function createDefault(): Configuration
{
return new Configuration();
@ -35,6 +37,15 @@ class Configuration
$config->setAllowAnonymousSubscribe(boolval($subscribe['allow_anonymous']));
}
if (isset($yaml['listeners'])) {
foreach ($yaml['listeners'] as $listener) {
if (!is_array($listener)) {
throw new \Exception("Bad listener config");
}
$config->addListener($listener);
}
}
return $config;
}
@ -70,5 +81,28 @@ class Configuration
$this->allowAnonymousSubscribe = $allowAnonymousSubscribe;
return $this;
}
function addListener(array $config): self
{
$this->listeners[] = [
'address' => $config['address']??throw new \Exception("Address can't be empty"),
'cors' => isset($config['cors'])?[
'allow_origin' => $config['cors']['allow_origin']??'*',
'csp' => $config['cors']['csp']??'default-src * \'self\'',
]:[
'allow_origin' => '*',
'csp' => 'default-src * \'self\'',
],
'websocket' => isset($config['websocket'])?[
'enable' => $config['websocket']['enable']??false
]:null,
];
return $this;
}
public function getListeners(): array
{
return $this->listeners;
}
}