Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Dec 19, 2024
1 parent 1462c27 commit 7a7d6bc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
37 changes: 30 additions & 7 deletions src/Providers/AddonServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ abstract class AddonServiceProvider extends ServiceProvider

public function boot()
{
$this->bootedAddons = $this->app->make('statamic.booted-addons');
$this->autoloadedClasses = $this->app->make('statamic.autoloaded-addon-classes');

Statamic::booted(function () {
if (! $this->getAddon()) {
return;
Expand Down Expand Up @@ -225,7 +222,7 @@ public function boot()
->bootPublishAfterInstall()
->bootAddon();

$this->bootedAddons[] = $this->getAddon()->id();
$this->bootedAddons()->push($this->getAddon()->id());
});
}

Expand Down Expand Up @@ -838,12 +835,12 @@ protected function autoloadFilesFromFolder($folder, $requiredClass = null)
continue;
}

if ($this->autoloadedClasses->contains($fqcn)) {
if ($this->autoloadedClasses()->contains($fqcn)) {
continue;
}

$autoloadable[] = $fqcn;
$this->autoloadedClasses[] = $fqcn;
$this->autoloadedClasses()->push($fqcn);
}

return $autoloadable;
Expand All @@ -856,7 +853,7 @@ private function shouldBootRootItems()
// We'll keep track of addons that have been booted to ensure that multiple
// providers don't try to boot things twice. This could happen if there are
// multiple providers in the root autoload directory (src) of an addon.
if ($this->bootedAddons->contains($addon->id())) {
if ($this->bootedAddons()->contains($addon->id())) {
return false;
}

Expand All @@ -869,4 +866,30 @@ private function shouldBootRootItems()

return $thisDir === $autoloadDir;
}

private function autoloadedClasses()
{
if ($this->autoloadedClasses) {
return $this->autoloadedClasses;
}

if (! $this->app->bound($autoloaded = 'statamic.autoloaded-addon-classes')) {
$this->app->instance($autoloaded, collect());
}

return $this->autoloadedClasses = $this->app->make($autoloaded);
}

private function bootedAddons()
{
if ($this->bootedAddons) {
return $this->bootedAddons;
}

if (! $this->app->bound($booted = 'statamic.booted-addons')) {
$this->app->instance($booted, collect());
}

return $this->bootedAddons = $this->app->make($booted);
}
}
3 changes: 0 additions & 3 deletions src/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ public function boot()
$this->addAboutCommandInfo();

$this->app->make(Schedule::class)->job(new HandleEntrySchedule)->everyMinute();

$this->app->instance('statamic.booted-addons', collect());
$this->app->instance('statamic.autoloaded-addon-classes', collect());
}

public function register()
Expand Down

0 comments on commit 7a7d6bc

Please sign in to comment.