mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-09 18:19: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;
|
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
|
public function getProviders(): array
|
||||||
{
|
{
|
||||||
$class = $this->fullClass();
|
$providers = File::allFiles(plugin_path($this->id, 'src', 'Providers'));
|
||||||
if (class_exists($class) && method_exists($class, 'getProviders')) {
|
|
||||||
return ($class)::getProviders();
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
public function getCommands(): array
|
||||||
{
|
{
|
||||||
$class = $this->fullClass();
|
$providers = File::allFiles(plugin_path($this->id, 'src', 'Console', 'Commands'));
|
||||||
if (class_exists($class) && method_exists($class, 'getCommands')) {
|
|
||||||
return ($class)::getCommands();
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
// Register service providers
|
||||||
foreach ($plugin->getProviders() as $provider) {
|
foreach ($plugin->getProviders() as $provider) {
|
||||||
if (!class_exists($provider) || !is_subclass_of($provider, ServiceProvider::class)) {
|
if (!class_exists($provider) || !is_subclass_of($provider, ServiceProvider::class)) {
|
||||||
throw new Exception('Provider class "' . $provider . '" not found');
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->app->register($provider);
|
$this->app->register($provider);
|
||||||
@ -71,7 +71,7 @@ class PluginService
|
|||||||
// Resolve artisan commands
|
// Resolve artisan commands
|
||||||
foreach ($plugin->getCommands() as $command) {
|
foreach ($plugin->getCommands() as $command) {
|
||||||
if (!class_exists($command) || !is_subclass_of($command, Command::class)) {
|
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) {
|
ConsoleApplication::starting(function ($artisan) use ($command) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user