Add logging and instance configurations

This commit is contained in:
netkas 2024-10-30 15:12:55 -04:00
parent 8334816d35
commit 99a4f20ece
5 changed files with 261 additions and 12 deletions

View file

@ -26,9 +26,9 @@ class CacheConfiguration
$this->password = $data['password'] ? (string)$data['password'] : null;
$this->database = $data['database'] ? (int)$data['database'] : null;
$this->sessionsEnabled = (bool)$data['sessions.enabled'];
$this->sessionsTtl = (int)$data['sessions.ttl'];
$this->sessionsMax = (int)$data['sessions.max'];
$this->sessionsEnabled = (bool)$data['sessions']['enabled'];
$this->sessionsTtl = (int)$data['sessions']['ttl'];
$this->sessionsMax = (int)$data['sessions']['max'];
}
public function isEnabled(): bool

View file

@ -0,0 +1,76 @@
<?php
namespace Socialbox\Classes\Configuration;
class InstanceConfiguration
{
private bool $enabled;
private ?string $domain;
private ?string $rpcEndpoint;
private ?string $privateKey;
private ?string $publicKey;
/**
* Constructor that initializes object properties with the provided data.
*
* @param array $data An associative array with keys 'enabled', 'domain', 'private_key', and 'public_key'.
* @return void
*/
public function __construct(array $data)
{
$this->enabled = (bool)$data['enabled'];
$this->domain = $data['domain'];
$this->rpcEndpoint = $data['rpc_endpoint'];
$this->privateKey = $data['private_key'];
$this->publicKey = $data['public_key'];
}
/**
* Checks if the current object is enabled.
*
* @return bool True if the object is enabled, false otherwise.
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Retrieves the domain.
*
* @return string|null The domain.
*/
public function getDomain(): ?string
{
return $this->domain;
}
/**
* @return string|null
*/
public function getRpcEndpoint(): ?string
{
return $this->rpcEndpoint;
}
/**
* Retrieves the private key.
*
* @return string|null The private key.
*/
public function getPrivateKey(): ?string
{
return $this->privateKey;
}
/**
* Retrieves the public key.
*
* @return string|null The public key.
*/
public function getPublicKey(): ?string
{
return $this->publicKey;
}
}

View file

@ -0,0 +1,115 @@
<?php
namespace Socialbox\Classes\Configuration;
use LogLib\Enums\LogLevel;
class LoggingConfiguration
{
private bool $consoleLoggingEnabled;
private string $consoleLoggingLevel;
private bool $fileLoggingEnabled;
private string $fileLoggingLevel;
/**
* Initializes a new instance of the class with the given configuration data.
*
* @param array $data An associative array containing logging configuration settings.
* @return void
*/
public function __construct(array $data)
{
$this->consoleLoggingEnabled = (bool) $data['console_logging_enabled'];
$this->consoleLoggingLevel = $data['console_logging_level'];
$this->fileLoggingEnabled = (bool) $data['file_logging_enabled'];
$this->fileLoggingLevel = $data['file_logging_level'];
}
/**
* Checks if console logging is enabled.
*
* @return bool True if console logging is enabled, otherwise false.
*/
public function isConsoleLoggingEnabled(): bool
{
return $this->consoleLoggingEnabled;
}
/**
* Retrieves the logging level for console output.
*
* @return LogLevel The logging level configured for console output.
*/
public function getConsoleLoggingLevel(): LogLevel
{
return $this->parseLogLevel($this->consoleLoggingLevel);
}
/**
* Checks if file logging is enabled.
*
* @return bool True if file logging is enabled, false otherwise.
*/
public function isFileLoggingEnabled(): bool
{
return $this->fileLoggingEnabled;
}
/**
* Retrieves the logging level for file logging.
*
* @return LogLevel The logging level set for file logging.
*/
public function getFileLoggingLevel(): LogLevel
{
return $this->parseLogLevel($this->fileLoggingLevel);
}
/**
* Parses the given log level from string format to a LogLevel enumeration.
*
* @param string $logLevel The log level as a string.
* @return LogLevel The corresponding LogLevel enumeration.
*/
private function parseLogLevel(string $logLevel): LogLevel
{
switch (strtolower($logLevel)) {
case LogLevel::DEBUG:
case 'debug':
case '6':
case 'dbg':
return LogLevel::DEBUG;
case LogLevel::VERBOSE:
case 'verbose':
case '5':
case 'vrb':
return LogLevel::VERBOSE;
default:
case LogLevel::INFO:
case 'info':
case '4':
case 'inf':
return LogLevel::INFO;
case LogLevel::WARNING:
case 'warning':
case '3':
case 'wrn':
return LogLevel::WARNING;
case LogLevel::ERROR:
case 'error':
case '2':
case 'err':
return LogLevel::ERROR;
case LogLevel::FATAL:
case 'fatal':
case '1':
case 'crt':
return LogLevel::FATAL;
case LogLevel::SILENT:
case 'silent':
case '0':
case 'sil':
return LogLevel::SILENT;
}
}
}

View file

@ -30,7 +30,7 @@ class RegistrationConfiguration
*/
public function __construct(array $data)
{
$this->registrationEnabled = (bool)$data['registration_enabled'];
$this->registrationEnabled = (bool)$data['enabled'];
$this->passwordRequired = (bool)$data['password_required'];
$this->otpRequired = (bool)$data['otp_required'];
$this->displayNameRequired = (bool)$data['display_name_required'];