feat: refactor server structure and introduce CLI application
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 3m6s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 3m25s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 3m27s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 3m18s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 3m16s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 1m50s

This commit is contained in:
2025-11-11 09:30:20 -05:00
parent 13445a0719
commit 8ccaaadf03
10 changed files with 284 additions and 89 deletions

76
src/Kernel.php Normal file
View File

@@ -0,0 +1,76 @@
<?php
namespace Siteworxpro\App;
use Illuminate\Container\Container;
use Illuminate\Database\Capsule\Manager;
use Illuminate\Support\ServiceProvider;
use Siteworx\Config\Config as SWConfig;
use Siteworxpro\App\Services\Facade;
use Siteworxpro\App\Services\Facades\Config;
use Siteworxpro\App\Services\ServiceProviders\LoggerServiceProvider;
use Siteworxpro\App\Services\ServiceProviders\RedisServiceProvider;
class Kernel
{
private static array $serviceProviders = [
LoggerServiceProvider::class,
RedisServiceProvider::class
];
/**
* Bootstraps the server by initializing the PSR-7 worker and router.
*
* This method sets up the PSR-7 worker and router instances, and registers
* the routes for the server. It should be called in the constructor of
* subclasses to ensure proper initialization.
*
* @return void
* @throws \ReflectionException
*/
public static function boot(): void
{
$container = new Container();
Facade::setFacadeContainer($container);
// Bind the container to the Config facade first so that it can be used by service providers
$container->bind(SWConfig::class, function () {
return SWConfig::load(__DIR__ . '/../config.php');
});
foreach (self::$serviceProviders as $serviceProvider) {
if (class_exists($serviceProvider)) {
$provider = new $serviceProvider($container);
if ($provider instanceof ServiceProvider) {
$provider->register();
} else {
throw new \RuntimeException(sprintf(
'Service provider %s is not an instance of ServiceProvider.',
$serviceProvider
));
}
} else {
throw new \RuntimeException(sprintf('Service provider %s not found.', $serviceProvider));
}
}
self::bootModelCapsule();
}
/**
* Bootstraps the model capsule for database connections.
*
* This method sets up the database connection using the Eloquent ORM.
* It retrieves the database configuration from the Config facade and
* initializes the Eloquent capsule manager.
*
* @return void
*/
private static function bootModelCapsule(): void
{
$capsule = new Manager();
$capsule->addConnection(Config::get('db'));
$capsule->setAsGlobal();
$capsule->bootEloquent();
}
}