Read config, handle lastEventId in topicmanager
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user