2024-03-10 03:06:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace NoccyLabs\Mercureact;
|
|
|
|
|
2024-03-11 02:15:04 +01:00
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
|
|
2024-03-10 03:06:19 +01:00
|
|
|
class Configuration
|
|
|
|
{
|
|
|
|
private ?string $publicUrl = null;
|
|
|
|
|
|
|
|
private ?string $jwtSecret = null;
|
|
|
|
|
2024-03-11 00:50:15 +01:00
|
|
|
private bool $allowAnonymousSubscribe = false;
|
|
|
|
|
2024-03-10 03:06:19 +01:00
|
|
|
public static function createDefault(): Configuration
|
|
|
|
{
|
|
|
|
return new Configuration();
|
|
|
|
}
|
|
|
|
|
2024-03-11 02:15:04 +01:00
|
|
|
public static function fromFile(string $file): Configuration
|
|
|
|
{
|
|
|
|
$config = new Configuration();
|
|
|
|
|
|
|
|
$yaml = Yaml::parseFile($file);
|
|
|
|
|
|
|
|
if (isset($yaml['security'])) {
|
|
|
|
$security = $yaml['security'];
|
|
|
|
if (isset($security['jwt_secret']))
|
|
|
|
$config->setJwtSecret($security['jwt_secret']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($yaml['subscribe'])) {
|
|
|
|
$subscribe = $yaml['subscribe'];
|
|
|
|
if (isset($subscribe['allow_anonymous']))
|
|
|
|
$config->setAllowAnonymousSubscribe(boolval($subscribe['allow_anonymous']));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
|
2024-03-10 03:06:19 +01:00
|
|
|
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;
|
|
|
|
}
|
2024-03-11 00:50:15 +01:00
|
|
|
|
|
|
|
function getAllowAnonymousSubscribe():bool
|
|
|
|
{
|
|
|
|
return $this->allowAnonymousSubscribe;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setAllowAnonymousSubscribe(bool $allowAnonymousSubscribe): self
|
|
|
|
{
|
|
|
|
$this->allowAnonymousSubscribe = $allowAnonymousSubscribe;
|
|
|
|
return $this;
|
|
|
|
}
|
2024-03-10 03:06:19 +01:00
|
|
|
}
|
|
|
|
|