diff --git a/.idea/php.xml b/.idea/php.xml
index f324872..2b1842c 100644
--- a/.idea/php.xml
+++ b/.idea/php.xml
@@ -10,6 +10,14 @@
+
+
+
+
+
+
+
+
diff --git a/project.json b/project.json
index 4cceb33..0f64f4b 100644
--- a/project.json
+++ b/project.json
@@ -38,6 +38,23 @@
"DEBUG": "1"
}
}
+ ],
+ "dependencies": [
+ {
+ "name": "net.nosial.configlib",
+ "version": "latest",
+ "source": "nosial/configlib=latest@github"
+ },
+ {
+ "name": "net.nosial.loglib2",
+ "version": "latest",
+ "source": "nosial/loglib2=latest@github"
+ },
+ {
+ "name": "net.nosial.optslib",
+ "version": "latest",
+ "source": "nosial/optslib=latest@github"
+ }
]
},
"execution_policies": [
diff --git a/src/FederationServer/Classes/Configuration.php b/src/FederationServer/Classes/Configuration.php
new file mode 100644
index 0000000..a76a4e7
--- /dev/null
+++ b/src/FederationServer/Classes/Configuration.php
@@ -0,0 +1,77 @@
+setDefault('database.host', '127.0.0.1');
+ self::$configuration->setDefault('database.port', 3306);
+ self::$configuration->setDefault('database.username', 'root');
+ self::$configuration->setDefault('database.password', 'root');
+ self::$configuration->setDefault('database.name', 'federation');
+ self::$configuration->setDefault('database.charset', 'utf8mb4');
+ self::$configuration->setDefault('database.collation', 'utf8mb4_unicode_ci');
+
+ self::$configuration->setDefault('redis.enabled', true);
+ self::$configuration->setDefault('redis.host', '127.0.1');
+ self::$configuration->setDefault('redis.port', 6379);
+ self::$configuration->setDefault('redis.password', null);
+ self::$configuration->setDefault('redis.database', 0);
+
+ self::$configuration->save();
+
+ self::$databaseConfiguration = new DatabaseConfiguration(self::$configuration->get('database'));
+ self::$redisConfiguration = new RedisConfiguration(self::$configuration->get('redis'));
+ }
+
+ public static function getConfiguration(): array
+ {
+ if(self::$configuration === null)
+ {
+ self::initialize();
+ }
+
+ return self::$configuration->getConfiguration();
+ }
+
+ public static function getConfigurationLib(): \ConfigLib\Configuration
+ {
+ if(self::$configuration === null)
+ {
+ self::initialize();
+ }
+
+ return self::$configuration;
+ }
+
+ public static function getDatabaseConfiguration(): DatabaseConfiguration
+ {
+ if(self::$databaseConfiguration === null)
+ {
+ self::initialize();
+ }
+
+ return self::$databaseConfiguration;
+ }
+
+ public static function getRedisConfiguration(): RedisConfiguration
+ {
+ if(self::$redisConfiguration === null)
+ {
+ self::initialize();
+ }
+
+ return self::$redisConfiguration;
+ }
+ }
\ No newline at end of file
diff --git a/src/FederationServer/Classes/Configuration/DatabaseConfiguration.php b/src/FederationServer/Classes/Configuration/DatabaseConfiguration.php
new file mode 100644
index 0000000..e43f842
--- /dev/null
+++ b/src/FederationServer/Classes/Configuration/DatabaseConfiguration.php
@@ -0,0 +1,118 @@
+host = $configuration['host'] ?? '127.0.0.1';
+ $this->port = $configuration['port'] ?? 3306;
+ $this->username = $configuration['username'] ?? 'root';
+ $this->password = $configuration['password'] ?? 'root';
+ $this->name = $configuration['name'] ?? 'federation';
+ $this->charset = $configuration['charset'] ?? 'utf8mb4';
+ $this->collation = $configuration['collation'] ?? 'utf8mb4_unicode_ci';
+ }
+
+ /**
+ * Get the database host.
+ *
+ * @return string
+ */
+ public function getHost(): string
+ {
+ return $this->host;
+ }
+
+ /**
+ * Get the database port.
+ *
+ * @return int
+ */
+ public function getPort(): int
+ {
+ return $this->port;
+ }
+
+ /**
+ * Get the database username.
+ *
+ * @return string
+ */
+ public function getUsername(): string
+ {
+ return $this->username;
+ }
+
+ /**
+ * Get the database password.
+ *
+ * @return string
+ */
+ public function getPassword(): string
+ {
+ return $this->password;
+ }
+
+ /**
+ * Get the database name.
+ *
+ * @return string
+ */
+ public function getName(): string
+ {
+ return $this->name;
+ }
+
+ /**
+ * Get the database charset.
+ *
+ * @return string
+ */
+ public function getCharset(): string
+ {
+ return $this->charset;
+ }
+
+ /**
+ * Get the database collation.
+ *
+ * @return string
+ */
+ public function getCollation(): string
+ {
+ return $this->collation;
+ }
+
+ /**
+ * Get the Data Source Name (DSN) for the database connection.
+ *
+ * @return string
+ */
+ public function getDsn(): string
+ {
+ return sprintf('mysql:host=%s;port=%d;dbname=%s;charset=%s',
+ $this->host, $this->port, $this->name, $this->charset
+ );
+ }
+ }
+
diff --git a/src/FederationServer/Classes/Configuration/RedisConfiguration.php b/src/FederationServer/Classes/Configuration/RedisConfiguration.php
new file mode 100644
index 0000000..0d2df52
--- /dev/null
+++ b/src/FederationServer/Classes/Configuration/RedisConfiguration.php
@@ -0,0 +1,76 @@
+enabled = $configuration['enabled'] ?? true;
+ $this->host = $configuration['host'] ?? '127.0.0.1';
+ $this->port = $configuration['port'] ?? 6379;
+ $this->password = $configuration['password'] ?? null;
+ $this->database = $configuration['database'] ?? 0;
+ }
+
+ /**
+ * Check if Redis is enabled.
+ *
+ * @return bool
+ */
+ public function isEnabled(): bool
+ {
+ return $this->enabled;
+ }
+
+ /**
+ * Get the Redis host.
+ *
+ * @return string
+ */
+ public function getHost(): string
+ {
+ return $this->host;
+ }
+
+ /**
+ * Get the Redis port.
+ *
+ * @return int
+ */
+ public function getPort(): int
+ {
+ return $this->port;
+ }
+
+ /**
+ * Get the Redis password.
+ *
+ * @return string|null
+ */
+ public function getPassword(): ?string
+ {
+ return $this->password;
+ }
+
+ /**
+ * Get the Redis database index.
+ *
+ * @return int
+ */
+ public function getDatabase(): int
+ {
+ return $this->database;
+ }
+ }
diff --git a/src/FederationServer/Classes/DatabaseConnection.php b/src/FederationServer/Classes/DatabaseConnection.php
new file mode 100644
index 0000000..cafd6fa
--- /dev/null
+++ b/src/FederationServer/Classes/DatabaseConnection.php
@@ -0,0 +1,37 @@
+getDsn(),
+ Configuration::getDatabaseConfiguration()->getUsername(),
+ Configuration::getDatabaseConfiguration()->getPassword(),
+ [
+ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
+ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
+ PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . Configuration::getDatabaseConfiguration()->getCharset() . ' COLLATE ' . Configuration::getDatabaseConfiguration()->getCollation(),
+ ]
+ );
+ }
+
+ return self::$pdo;
+ }
+ }
diff --git a/src/FederationServer/FederationServer.php b/src/FederationServer/FederationServer.php
new file mode 100644
index 0000000..ed7797d
--- /dev/null
+++ b/src/FederationServer/FederationServer.php
@@ -0,0 +1,8 @@
+