mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-08 10:39:27 +01:00
automatically discover providers & commands
This commit is contained in:
parent
4db0702970
commit
7ac298ffd5
@ -35,11 +35,4 @@ class $class$ implements Plugin
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
|
||||
public static function getProviders(): array
|
||||
{
|
||||
return [
|
||||
\$namespace$\Providers\$class$Provider::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Contracts\Plugins;
|
||||
|
||||
interface HasPluginCommands
|
||||
{
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCommands(): array;
|
||||
}
|
||||
@ -262,12 +262,9 @@ class Plugin extends Model implements HasPluginSettings
|
||||
*/
|
||||
public function getProviders(): array
|
||||
{
|
||||
$class = $this->fullClass();
|
||||
if (class_exists($class) && method_exists($class, 'getProviders')) {
|
||||
return ($class)::getProviders();
|
||||
}
|
||||
$providers = File::allFiles(plugin_path($this->id, 'src', 'Providers'));
|
||||
|
||||
return [];
|
||||
return array_map(fn ($provider) => $this->namespace . '\\Providers\\' . str($provider->getRelativePathname())->remove('.php', false), $providers);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -275,11 +272,8 @@ class Plugin extends Model implements HasPluginSettings
|
||||
*/
|
||||
public function getCommands(): array
|
||||
{
|
||||
$class = $this->fullClass();
|
||||
if (class_exists($class) && method_exists($class, 'getCommands')) {
|
||||
return ($class)::getCommands();
|
||||
}
|
||||
$providers = File::allFiles(plugin_path($this->id, 'src', 'Console', 'Commands'));
|
||||
|
||||
return [];
|
||||
return array_map(fn ($provider) => $this->namespace . '\\Console\\Commands\\' . str($provider->getRelativePathname())->remove('.php', false), $providers);
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ class PluginService
|
||||
// Register service providers
|
||||
foreach ($plugin->getProviders() as $provider) {
|
||||
if (!class_exists($provider) || !is_subclass_of($provider, ServiceProvider::class)) {
|
||||
throw new Exception('Provider class "' . $provider . '" not found');
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->app->register($provider);
|
||||
@ -71,7 +71,7 @@ class PluginService
|
||||
// Resolve artisan commands
|
||||
foreach ($plugin->getCommands() as $command) {
|
||||
if (!class_exists($command) || !is_subclass_of($command, Command::class)) {
|
||||
throw new Exception('Command class "' . $command . '" not found');
|
||||
continue;
|
||||
}
|
||||
|
||||
ConsoleApplication::starting(function ($artisan) use ($command) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user