From 47b8e276f4be964ec279b8aae0e7190c9a658148 Mon Sep 17 00:00:00 2001 From: Yassine <108750248+yassiNebeL@users.noreply.github.com> Date: Mon, 21 Oct 2024 21:14:20 +0100 Subject: [PATCH] refactor(web): resolve `HttpApplication` via the container (#1) resolving `HttpApplication` via the container, and setting-up the `Singleton` attribute. --- src/Tempest/Http/src/HttpApplication.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Tempest/Http/src/HttpApplication.php b/src/Tempest/Http/src/HttpApplication.php index 0bcaf20e5..38302a9bd 100644 --- a/src/Tempest/Http/src/HttpApplication.php +++ b/src/Tempest/Http/src/HttpApplication.php @@ -5,6 +5,7 @@ namespace Tempest\Http; use Tempest\Container\Container; +use Tempest\Container\Singleton; use Tempest\Core\AppConfig; use Tempest\Core\Application; use Tempest\Core\Kernel; @@ -16,6 +17,7 @@ use Tempest\Support\PathHelper; use Throwable; +#[Singleton] final readonly class HttpApplication implements Application { public function __construct(private Container $container) @@ -29,17 +31,11 @@ public static function boot( ): self { $container = Tempest::boot($root, $discoveryLocations); - // Application, - // TODO: can be refactored to resolve via the container - $application = new HttpApplication($container); - - $container->singleton(Application::class, fn () => $application); - - $root = $container->get(Kernel::class)->root; + $application = $container->get(HttpApplication::class); // Application-specific setup $logConfig = $container->get(LogConfig::class); - $logConfig->debugLogPath = PathHelper::make($root, '/log/debug.log'); + $logConfig->debugLogPath = PathHelper::make($container->get(Kernel::class)->root, '/log/debug.log'); $logConfig->serverLogPath = env('SERVER_LOG'); $logConfig->channels[] = new AppendLogChannel(PathHelper::make($root, '/log/tempest.log'));