mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 20:17:24 +08:00
improve plugin store
This commit is contained in:
@@ -27,7 +27,7 @@ abstract class BasePlugin extends BaseRepository
|
||||
|
||||
public function checkMainApplicationVersion()
|
||||
{
|
||||
$constantName = "static::COMPATIBLE_VERSION";
|
||||
$constantName = "static::COMPATIBLE_NP_VERSION";
|
||||
if (defined($constantName) && version_compare(VERSION_NUMBER, constant($constantName), '<')) {
|
||||
throw new \RuntimeException(sprintf(
|
||||
"NexusPHP version: %s is too low, this plugin require: %s",
|
||||
@@ -57,4 +57,17 @@ abstract class BasePlugin extends BaseRepository
|
||||
{
|
||||
return Plugin::getById(static::ID);
|
||||
}
|
||||
|
||||
public function getVersion(): string
|
||||
{
|
||||
$constantName = "static::VERSION";
|
||||
return defined($constantName) ? constant($constantName) : '';
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
$className = str_replace("Repository", "", get_called_class());
|
||||
$plugin = call_user_func([$className, "make"]);
|
||||
return $plugin->getId();
|
||||
}
|
||||
}
|
||||
|
||||
+13
-6
@@ -5,6 +5,9 @@ class Plugin
|
||||
{
|
||||
private static mixed $providers = null;
|
||||
|
||||
/**
|
||||
* @var BasePlugin[]
|
||||
*/
|
||||
private static array $plugins = [];
|
||||
|
||||
// public function __construct()
|
||||
@@ -28,7 +31,7 @@ class Plugin
|
||||
$result = [];
|
||||
//plugins are more exactly
|
||||
foreach (self::$plugins as $id => $plugin) {
|
||||
$result[$id] = 1;
|
||||
$result[$id] = $plugin->getVersion();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
@@ -60,15 +63,19 @@ class Plugin
|
||||
if ($parts[0] == 'NexusPlugin') {
|
||||
$className = str_replace('ServiceProvider', 'Repository', $provider);
|
||||
if (class_exists($className)) {
|
||||
$constantName = "$className::COMPATIBLE_VERSION";
|
||||
$constantName = "$className::COMPATIBLE_NP_VERSION";
|
||||
if (defined($constantName) && version_compare(VERSION_NUMBER, constant($constantName), '<')) {
|
||||
continue;
|
||||
}
|
||||
/**
|
||||
* @var BasePlugin $className
|
||||
*/
|
||||
$plugin = new $className;
|
||||
$pluginIdName = "$className::ID";
|
||||
if (defined($pluginIdName)) {
|
||||
self::$plugins[constant($pluginIdName)] = $plugin;
|
||||
}
|
||||
// $pluginIdName = "$className::ID";
|
||||
// if (defined($pluginIdName)) {
|
||||
// self::$plugins[constant($pluginIdName)] = $plugin;
|
||||
// }
|
||||
self::$plugins[$plugin->getId()] = $plugin;
|
||||
call_user_func([$plugin, 'boot']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user