From 109aa691504437410cdb27c9b7353ecd234de975 Mon Sep 17 00:00:00 2001 From: Brent Roose Date: Wed, 4 Sep 2024 13:37:49 +0200 Subject: [PATCH] Cleanup --- src/Tempest/Core/Kernel.php | 10 ---------- src/Tempest/Core/Tempest.php | 13 +++++++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Tempest/Core/Kernel.php b/src/Tempest/Core/Kernel.php index 43e28b3c7..d9d31639b 100644 --- a/src/Tempest/Core/Kernel.php +++ b/src/Tempest/Core/Kernel.php @@ -19,16 +19,6 @@ public function __construct( public function init(): Container { - register_shutdown_function(function (): void { - $error = error_get_last(); - - $message = $error['message'] ?? ''; - - if (str_contains($message, 'Cannot declare class')) { - echo "Does this class have the right namespace?" . PHP_EOL; - } - }); - $container = $this->createContainer(); $bootstraps = [ diff --git a/src/Tempest/Core/Tempest.php b/src/Tempest/Core/Tempest.php index 1a11ba8e0..15ed9a710 100644 --- a/src/Tempest/Core/Tempest.php +++ b/src/Tempest/Core/Tempest.php @@ -12,6 +12,19 @@ { public static function boot(?string $root = null, ?AppConfig $appConfig = null): Container { + // Fix for classes that don't have a proper PSR-4 namespace, + // they break discovery with an unrecoverable error, + // but you don't know why because PHP simply says "duplicate classname" instead of something reasonable. + register_shutdown_function(function (): void { + $error = error_get_last(); + + $message = $error['message'] ?? ''; + + if (str_contains($message, 'Cannot declare class')) { + echo "Does this class have the right namespace?" . PHP_EOL; + } + }); + $root ??= getcwd(); // Env