This commit is contained in:
2025-04-25 20:46:09 -04:00
parent 9bdecb1455
commit e84c7cf9ad
11 changed files with 2056 additions and 55 deletions

View File

@@ -5,6 +5,9 @@ declare(strict_types=1);
namespace Siteworxpro\App\Facades;
use Illuminate\Support\Facades\Facade;
use Siteworx\Config\Exception\EmptyDirectoryException;
use Siteworx\Config\Exception\FileNotFoundException;
use Siteworx\Config\Exception\UnsupportedFormatException;
/**
* Class Config
@@ -12,24 +15,20 @@ use Illuminate\Support\Facades\Facade;
* This class serves as a facade for the configuration settings of the application.
* It extends the Facade class from the Illuminate\Support\Facades namespace.
*
* @method static string|int|bool|float get(string $key, string $castTo = 'string') Retrieve the configuration value for the given key.
* @method static string|int|bool|float get(string $key) Retrieve the configuration value for the given key.
*
* @package Siteworx\App\Facades
*/
class Config extends Facade
{
public const string HTTP_PORT = 'HTTP_PORT';
public const string LOG_LEVEL = 'LOG_LEVEL';
public const string DB_DRIVER = 'DB_DRIVER';
public const string DB_HOST = 'DB_HOST';
public const string DB_DATABASE = 'DB_DATABASE';
public const string DB_USER = 'DB_USER';
public const string DB_PASSWORD = 'DB_PASSWORD';
public const string DEV_MODE = 'DEV_MODE';
public static function getFacadeRoot(): \Siteworxpro\App\Helpers\Config
/**
* @throws UnsupportedFormatException
* @throws FileNotFoundException
* @throws EmptyDirectoryException
*/
public static function getFacadeRoot(): \Siteworx\Config\Config
{
return new \Siteworxpro\App\Helpers\Config();
return \Siteworx\Config\Config::load(__DIR__ . '/../../config.php');
}
/**
@@ -39,6 +38,6 @@ class Config extends Facade
*/
protected static function getFacadeAccessor(): string
{
return \Siteworxpro\App\Helpers\Config::class;
return 'config';
}
}

View File

@@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
namespace Siteworxpro\App\Helpers;
use Psr\Log\LogLevel;
use Siteworxpro\App\Facades\Config as FacadeConfig;
class Config
{
private const array DEFAULTS = [
FacadeConfig::DB_DRIVER => 'pgsql',
FacadeConfig::DB_HOST => 'localhost',
FacadeConfig::DB_DATABASE => 'siteworx',
FacadeConfig::DB_USER => 'siteworx',
FacadeConfig::DB_PASSWORD => 'password',
FacadeConfig::LOG_LEVEL => LogLevel::DEBUG,
FacadeConfig::HTTP_PORT => '9501',
FacadeConfig::DEV_MODE => true,
];
/**
* @param string $key
* @param string $castTo
* @return string|int|bool|float
*/
public function get(string $key, string $castTo = 'string'): string|int|bool|float
{
return Env::get($key, self::DEFAULTS[$key] ?? null, $castTo);
}
}

View File

@@ -84,11 +84,11 @@ class Server
{
$capsule = new \Illuminate\Database\Capsule\Manager();
$capsule->addConnection([
'driver' => Config::get(Config::DB_DRIVER),
'host' => Config::get(Config::DB_HOST),
'database' => Config::get(Config::DB_DATABASE),
'username' => Config::get(Config::DB_USER),
'password' => Config::get(Config::DB_PASSWORD),
'driver' => Config::get('db.driver'),
'host' => Config::get('db.host'),
'database' => Config::get('db.database'),
'username' => Config::get('db.username'),
'password' => Config::get('db.password'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
@@ -128,7 +128,7 @@ class Server
{
Logger::info(sprintf('Server started: %s', microtime(true)));
Logger::info(sprintf('Server PID: %s', getmypid()));
Logger::info(sprintf('Server Listening on: %s:%s', Config::get('HTTP_HOST'), Config::get('HTTP_PORT')));
Logger::info(sprintf('Server Listening on: 0.0.0.0:%s', Config::get('server.port')));
while (true) {
try {