setJwtSecret($security['jwt_secret']); } if (isset($yaml['subscribe'])) { $subscribe = $yaml['subscribe']; if (isset($subscribe['allow_anonymous'])) $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; } public function setPublicUrl(string $publicUrl): self { $this->publicUrl = $publicUrl; return $this; } public function getPublicUrl(): ?string { return $this->publicUrl; } public function setJwtSecret(string $secret): self { $this->jwtSecret = $secret; return $this; } public function getJwtSecret(): ?string { return $this->jwtSecret; } function getAllowAnonymousSubscribe():bool { return $this->allowAnonymousSubscribe; } function setAllowAnonymousSubscribe(bool $allowAnonymousSubscribe): self { $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\'', ], ]; return $this; } public function getListeners(): array { return $this->listeners; } }