diff --git a/src/lib/Core/Bootstrap.php b/src/lib/Core/Bootstrap.php index 6756e3e..302ba92 100755 --- a/src/lib/Core/Bootstrap.php +++ b/src/lib/Core/Bootstrap.php @@ -62,10 +62,13 @@ public static function start( bool $dieOnChange = false, ): void { try { - Container::requireLibraries($libraries)->unwrap($requireError); - if ($requireError) { - self::kill((string)$requireError); + foreach (explode(',', $libraries) as $library) { + Container::requireLibraries($library)->unwrap($requireError); + if ($requireError) { + self::kill((string)$requireError); + } } + Container::loadDefaultProviders($name)->unwrap($initializeError); if ($initializeError) { self::kill((string)$initializeError); @@ -208,10 +211,13 @@ public static function spawn( EventLoop::onSignal(SIGQUIT, static fn () => self::kill("Killing application...")); EventLoop::onSignal(SIGTERM, static fn () => self::kill("Killing application...")); - Container::requireLibraries($libraries)->unwrap($requireError); - if ($requireError) { - self::kill((string)$requireError); + foreach (explode(',', $libraries) as $library) { + Container::requireLibraries($library)->unwrap($requireError); + if ($requireError) { + self::kill((string)$requireError); + } } + Container::loadDefaultProviders("Watcher")->unwrap($initializeError); if ($initializeError) { self::kill((string)$initializeError); diff --git a/src/lib/Core/Container.php b/src/lib/Core/Container.php index 2c57ded..dc0bf2b 100755 --- a/src/lib/Core/Container.php +++ b/src/lib/Core/Container.php @@ -80,6 +80,33 @@ public static function requireLibraries(string $librariesPath):Unsafe { * @return Unsafe */ public static function loadDefaultProviders(string $applicationName):Unsafe { + // Making sure providers load correctly. + $providersLoaded = match (false) { + class_exists($className = \CatPaw\Core\Implementations\Environment\SimpleEnvironment::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Queue\Implementations\Queue\SimpleQueue::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\RaspberryPi\Implementations\Gpio\SimpleGpio::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Schedule\Implementations\Schedule\SimpleSchedule::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Store\Implementations\Store\SimpleState::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Web\Implementations\ByteRange\SimpleByteRange::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Web\Implementations\FileServer\SimpleFileServer::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Web\Implementations\FileServer\SpaFileServer::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Web\Implementations\HttpInvoker\SimpleHttpInvoker::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Web\Implementations\OpenApi\SimpleOpenApi::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Web\Implementations\OpenApiState\SimpleOpenApiState::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Web\Implementations\RequestHandler\SimpleRequestHandler::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Web\Implementations\RouteResolver\SimpleRouteResolver::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Web\Implementations\Router\SimpleRouter::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Web\Implementations\Server\SimpleServer::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Web\Implementations\ViewEngine\LatteViewEngine::class) => error("Could not load class $className"), + class_exists($className = \CatPaw\Web\Implementations\Websocket\SimpleWebsocket::class) => error("Could not load class $className"), + default => ok() + }; + + $providersLoaded->unwrap($error); + if ($error) { + return error($error); + } + /** @var LoggerInterface $logger */ $logger = LoggerFactory::create(loggerName: $applicationName)->unwrap($error); if ($error) {