Skip to content

Commit

Permalink
Lazy load plugin license info
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Dec 4, 2024
1 parent 56754d4 commit e289350
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Plugin/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class Plugin
{
protected Assets $assets;
protected License $license;
protected License|Closure|array|string $license;
protected UpdateStatus|null $updateStatus = null;

/**
Expand Down Expand Up @@ -69,14 +69,9 @@ public function __construct(
}

// read composer.json and use as info fallback
$info = Data::read($this->manifest(), fail: false);
$this->info = [...$info, ...$this->info];

// set the license
$this->license = License::from(
plugin: $this,
license: $license ?? $this->info['license'] ?? '-'
);
$info = Data::read($this->manifest(), fail: false);
$this->info = [...$info, ...$this->info];
$this->license = $license ?? $this->info['license'] ?? '-';
}

/**
Expand Down Expand Up @@ -179,7 +174,15 @@ public function link(): string|null
*/
public function license(): License
{
return $this->license;
if ($this->license instanceof License) {
return $this->license;
}

// resolve license info from Closure, array or string
return $this->license = License::from(
plugin: $this,
license: $this->license
);
}

/**
Expand Down

0 comments on commit e289350

Please sign in to comment.