Add ServerConfiguration for managing server settings and API key
Some checks are pending
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
Some checks are pending
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
This commit is contained in:
parent
877a028407
commit
f72cc638ef
2 changed files with 61 additions and 0 deletions
|
@ -5,9 +5,11 @@
|
|||
use FederationServer\Classes\Configuration\DatabaseConfiguration;
|
||||
use FederationServer\Classes\Configuration\RedisConfiguration;
|
||||
use FederationServer\Classes\Configuration\FileStorageConfiguration;
|
||||
use FederationServer\Classes\Configuration\ServerConfiguration;
|
||||
|
||||
class Configuration
|
||||
{
|
||||
private static ?ServerConfiguration $serverConfiguration = null;
|
||||
private static ?\ConfigLib\Configuration $configuration = null;
|
||||
private static ?DatabaseConfiguration $databaseConfiguration = null;
|
||||
private static ?RedisConfiguration $redisConfiguration = null;
|
||||
|
@ -20,6 +22,9 @@
|
|||
{
|
||||
self::$configuration = new \ConfigLib\Configuration('federation_server');
|
||||
|
||||
self::$configuration->setDefault('server.name', 'Federation Server');
|
||||
self::$configuration->setDefault('server.api_key', Utilities::generateString());
|
||||
|
||||
self::$configuration->setDefault('database.host', '127.0.0.1');
|
||||
self::$configuration->setDefault('database.port', 3306);
|
||||
self::$configuration->setDefault('database.username', 'root');
|
||||
|
@ -39,6 +44,7 @@
|
|||
|
||||
self::$configuration->save();
|
||||
|
||||
self::$serverConfiguration = new ServerConfiguration(self::$configuration->get('server'));
|
||||
self::$databaseConfiguration = new DatabaseConfiguration(self::$configuration->get('database'));
|
||||
self::$redisConfiguration = new RedisConfiguration(self::$configuration->get('redis'));
|
||||
self::$fileStorageConfiguration = new FileStorageConfiguration(self::$configuration->get('file_storage'));
|
||||
|
@ -74,6 +80,21 @@
|
|||
return self::$configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the server configuration.
|
||||
*
|
||||
* @return ServerConfiguration
|
||||
*/
|
||||
public static function getServerConfiguration(): ServerConfiguration
|
||||
{
|
||||
if(self::$serverConfiguration === null)
|
||||
{
|
||||
self::initialize();
|
||||
}
|
||||
|
||||
return self::$serverConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the database, Redis, and file storage configurations.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace FederationServer\Classes\Configuration;
|
||||
|
||||
class ServerConfiguration
|
||||
{
|
||||
private string $name;
|
||||
private ?string $apiKey;
|
||||
|
||||
/**
|
||||
* ServerConfiguration constructor.
|
||||
*
|
||||
* @param array $config Configuration array containing server settings.
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
$this->name = $config['server.name'] ?? 'Federation Server';
|
||||
$this->apiKey = $config['server.api_key'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the server.
|
||||
*
|
||||
* @return string The name of the server.
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the master API key for the server.
|
||||
*
|
||||
* @return string|null The API key, or null if not set.
|
||||
*/
|
||||
public function getApiKey(): ?string
|
||||
{
|
||||
return $this->apiKey;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue