From b730e620cecbb1a5921efaccc2023ff57caa9f51 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Tue, 1 Oct 2024 11:58:49 -0400 Subject: [PATCH] fix differently --- src/Providers/AddonServiceProvider.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Providers/AddonServiceProvider.php b/src/Providers/AddonServiceProvider.php index 4f6f96102e..6c507fa5da 100644 --- a/src/Providers/AddonServiceProvider.php +++ b/src/Providers/AddonServiceProvider.php @@ -345,7 +345,7 @@ protected function bootPolicies() protected function bootCommands() { - if ($this->app->isBooted() && $this->app->runningInConsole()) { + if ($this->app->runningInConsole()) { $commands = collect($this->commands) ->merge($this->autoloadFilesFromFolder('Commands', Command::class)) ->merge($this->autoloadFilesFromFolder('Console/Commands', Command::class)) @@ -704,7 +704,15 @@ protected function bootFieldsets() protected function autoloadFilesFromFolder($folder, $requiredClass) { - $addon = $this->getAddon(); + try { + $addon = $this->getAddon(); + } catch (NotBootedException $e) { + // This would be thrown if a developer has tried to call a method + // that triggers autoloading before Statamic has booted. Perhaps + // they have placed it in the boot method instead of bootAddon. + return []; + } + $path = $addon->directory().$addon->autoload().'/'.$folder; if (! $this->app['files']->exists($path)) {