refactor: unified kernal logic clean up

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-07-27 08:54:37 -04:00
parent 65c1b5fb75
commit eb99eb5a2e
10 changed files with 197 additions and 130 deletions
+23 -44
View File
@@ -12,6 +12,8 @@ namespace KTXC;
use KTXC\Application\KernelOptions;
use KTXC\Application\Execution\ExecutionDescriptor;
use KTXC\Application\Execution\ExecutionOutcome;
use KTXC\Application\Execution\ExecutionRunner;
use KTXC\Application\Execution\ExecutionRunnerInterface;
use KTXC\Application\Execution\ExecutionScope;
use KTXC\Application\Execution\TerminationReport;
use KTXC\Context\IdentityContext;
@@ -52,6 +54,7 @@ class Kernel implements KernelInterface
protected ?LoggerInterface $logger = null;
private bool $errorHandlerInstalled = false;
private ?ExecutionScope $activeScope = null;
private ?ExecutionRunnerInterface $runner = null;
private array $config;
@@ -67,6 +70,7 @@ class Kernel implements KernelInterface
$this->initialized = false;
$this->booted = false;
$this->container = null;
$this->runner = null;
}
private function initialize(): void
@@ -84,7 +88,10 @@ class Kernel implements KernelInterface
}
// Create logger from config (driver + level-filter; per-tenant wrapping applied later in DI)
$this->logger = LoggerFactory::create($this->config, $this->folderRoot());
$this->logger = LoggerFactory::create(
$this->config,
$this->options->paths->project,
);
$this->initializeErrorHandlers();
@@ -162,6 +169,11 @@ class Kernel implements KernelInterface
}
}
public function executionRunner(): ExecutionRunnerInterface
{
return $this->runner ??= new ExecutionRunner($this);
}
public function reboot(): void
{
$this->shutdown();
@@ -284,8 +296,12 @@ class Kernel implements KernelInterface
*/
protected function parameters(): array
{
$projectDir = $this->options->paths->project;
$cacheDir = $this->options->paths->cache($this->environment());
$logsDir = $this->options->paths->logs();
return [
'kernel.project_dir' => realpath($this->folderRoot()) ?: $this->folderRoot(),
'kernel.project_dir' => realpath($projectDir) ?: $projectDir,
'kernel.environment' => $this->environment(),
'kernel.runtime_environment' => '%env(default:kernel.environment:APP_RUNTIME_ENV)%',
'kernel.runtime_mode' => '%env(query_string:default:container.runtime_mode:APP_RUNTIME_MODE)%',
@@ -293,10 +309,10 @@ class Kernel implements KernelInterface
'kernel.runtime_mode.cli' => '%env(not:default:kernel.runtime_mode.web:)%',
'kernel.runtime_mode.worker' => '%env(bool:default::key:worker:default:kernel.runtime_mode:)%',
'kernel.debug' => $this->debug(),
'kernel.build_dir' => realpath($this->getBuildDir()) ?: $this->getBuildDir(),
'kernel.cache_dir' => realpath($this->getCacheDir()) ?: $this->getCacheDir(),
'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
'kernel.charset' => $this->getCharset(),
'kernel.build_dir' => realpath($cacheDir) ?: $cacheDir,
'kernel.cache_dir' => realpath($cacheDir) ?: $cacheDir,
'kernel.logs_dir' => realpath($logsDir) ?: $logsDir,
'kernel.charset' => 'UTF-8',
];
}
@@ -324,43 +340,6 @@ class Kernel implements KernelInterface
return $this->debug() && null !== $this->startTime ? $this->startTime : -\INF;
}
/**
* Gets the application root dir (path of the project's composer file).
*/
public function folderRoot(): string
{
return $this->options->paths->project;
}
/**
* Gets the path to the configuration directory.
*/
private function getConfigDir(): string
{
return $this->options->paths->configuration();
}
public function getCacheDir(): string
{
return $this->options->paths->cache($this->environment());
}
public function getBuildDir(): string
{
return $this->getCacheDir();
}
public function getLogDir(): string
{
return $this->options->paths->logs();
}
public function getCharset(): string
{
return 'UTF-8';
}
/**
* Initializes the service container
*/
@@ -393,7 +372,7 @@ class Kernel implements KernelInterface
protected function configureContainer(Builder $builder): void
{
// Service definitions
$projectDir = $this->folderRoot();
$projectDir = $this->options->paths->project;
$moduleDir = $projectDir . '/modules';
$environment = $this->environment();