From d9d6b204fd71e0463cbac4a4d35e7efb208d6f4c Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Tue, 1 Oct 2024 17:13:01 +0100 Subject: [PATCH] [5.x] Prevent autoloading addon files causing exception when called early (#10875) Co-authored-by: Jason Varga --- src/Providers/AddonServiceProvider.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Providers/AddonServiceProvider.php b/src/Providers/AddonServiceProvider.php index af4d04c6bb..10317262cc 100644 --- a/src/Providers/AddonServiceProvider.php +++ b/src/Providers/AddonServiceProvider.php @@ -728,7 +728,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)) {