mirror of
https://github.com/pelican-dev/panel.git
synced 2026-05-04 18:00:48 +03:00
Improve plugin loading (#2233)
This commit is contained in:
7
app/Exceptions/PluginIdMismatchException.php
Normal file
7
app/Exceptions/PluginIdMismatchException.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class PluginIdMismatchException extends Exception {}
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use App\Contracts\Plugins\HasPluginSettings;
|
||||
use App\Enums\PluginCategory;
|
||||
use App\Enums\PluginStatus;
|
||||
use App\Exceptions\PluginIdMismatchException;
|
||||
use App\Facades\Plugins;
|
||||
use Exception;
|
||||
use Filament\Schemas\Components\Component;
|
||||
@@ -108,11 +109,14 @@ class Plugin extends Model implements HasPluginSettings
|
||||
continue;
|
||||
}
|
||||
|
||||
$plugin = Str::lower($plugin);
|
||||
|
||||
try {
|
||||
$data = File::json($path, JSON_THROW_ON_ERROR);
|
||||
$data['id'] = Str::lower($data['id']);
|
||||
|
||||
if ($data['id'] !== $plugin) {
|
||||
throw new Exception("Plugin id mismatch for folder name ($plugin) and id in plugin.json ({$data['id']})!");
|
||||
throw new PluginIdMismatchException("Plugin id mismatch for folder name ($plugin) and id in plugin.json ({$data['id']})!");
|
||||
}
|
||||
|
||||
$panels = null;
|
||||
@@ -158,12 +162,12 @@ class Plugin extends Model implements HasPluginSettings
|
||||
if (!$exception instanceof JsonException) {
|
||||
$plugins[] = [
|
||||
'id' => $data['id'] ?? Str::uuid(),
|
||||
'name' => $data['name'] ?? $plugin,
|
||||
'name' => $data['name'] ?? Str::headline($plugin),
|
||||
'author' => $data['author'] ?? 'Unknown',
|
||||
'version' => '0.0.0',
|
||||
'description' => 'Plugin.json is invalid!',
|
||||
'version' => $data['version'] ?? '0.0.0',
|
||||
'description' => $exception instanceof PluginIdMismatchException ? $exception->getMessage() : 'Plugin.json is invalid!',
|
||||
'category' => PluginCategory::Plugin->value,
|
||||
'url' => null,
|
||||
'url' => $data['url'] ?? null,
|
||||
'update_url' => null,
|
||||
'namespace' => 'Error',
|
||||
'class' => 'Error',
|
||||
@@ -197,7 +201,7 @@ class Plugin extends Model implements HasPluginSettings
|
||||
|
||||
public function shouldLoad(?string $panelId = null): bool
|
||||
{
|
||||
return ($this->status === PluginStatus::Enabled || $this->status === PluginStatus::Errored) && (is_null($panelId) || !$this->panels || in_array($panelId, explode(',', $this->panels)));
|
||||
return $this->fullClass() !== '\\Error\\Error' && ($this->status === PluginStatus::Enabled || $this->status === PluginStatus::Errored) && (is_null($panelId) || !$this->panels || in_array($panelId, explode(',', $this->panels)));
|
||||
}
|
||||
|
||||
public function canEnable(): bool
|
||||
|
||||
@@ -54,6 +54,10 @@ class PluginService
|
||||
}
|
||||
}
|
||||
|
||||
if ($plugin->namespace === 'Error') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Always autoload src directory to make sure all class names can be resolved (e.g. in migrations)
|
||||
$namespace = $plugin->namespace . '\\';
|
||||
if (!array_key_exists($namespace, $classLoader->getPrefixesPsr4())) {
|
||||
|
||||
Reference in New Issue
Block a user