resolve('paths.base'); $this->configure($basePath); $this->bindProviders($basePath); return $this; } public function run(): Response { return $this->dispatch($this->resolve('paths.base')); } private function configure(string $basePath) { $dotenv = Dotenv::createImmutable($basePath); $dotenv->load(); } private function bindProviders(string $basePath) { $providers = require "{$basePath}/config/providers.php"; foreach ($providers as $provider) { $instance = new $provider; if (method_exists($instance, 'bind')) { $instance->bind($this); } } } private function dispatch(string $basePath): Response { if (!$this->has(Router::class)) { $router = new Router(); $routes = require "{$basePath}/app/routes.php"; $routes($router); $this->bind(Router::class, fn() => $router); } $response = $this->resolve(Router::class)->dispatch(); if (!$response instanceof Response) { $response = $this->resolve('response')->content($response); } return $response; } }