Skip to content

Commit

Permalink
change static properties to collection in container
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Dec 18, 2024
1 parent 9fccb13 commit b851b08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Providers/AddonServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,15 @@ abstract class AddonServiceProvider extends ServiceProvider
*/
protected $translations = true;

private static array $autoloaded = [];
private $autoloadedClasses;

private static array $bootedAddons = [];
private $bootedAddons;

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 @@ -222,7 +225,7 @@ public function boot()
->bootPublishAfterInstall()
->bootAddon();

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

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

if (in_array($fqcn, static::$autoloaded)) {
if ($this->autoloadedClasses->contains($fqcn)) {
continue;
}

$autoloadable[] = $fqcn;
static::$autoloaded[] = $fqcn;
$this->autoloadedClasses[] = $fqcn;
}

return $autoloadable;
Expand All @@ -853,7 +856,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 (in_array($addon->id(), static::$bootedAddons)) {
if ($this->bootedAddons->contains($addon->id())) {
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ 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 b851b08

Please sign in to comment.