Skip to content

Commit

Permalink
[5.x] Prevent autoloading addon files causing exception when called e…
Browse files Browse the repository at this point in the history
…arly (#10875)

Co-authored-by: Jason Varga <[email protected]>
  • Loading branch information
ryanmitchell and jasonvarga authored Oct 1, 2024
1 parent c3c63e2 commit d9d6b20
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Providers/AddonServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit d9d6b20

Please sign in to comment.