mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-17 00:44:08 +00:00
Moved plugin extension requirement checks to PluginManager::checkPluginLoadability()
these don't really belong in PluginDescription.
This commit is contained in:
parent
aa408c9a97
commit
44508a138f
@ -30,13 +30,9 @@ use function array_map;
|
|||||||
use function array_values;
|
use function array_values;
|
||||||
use function is_array;
|
use function is_array;
|
||||||
use function is_string;
|
use function is_string;
|
||||||
use function phpversion;
|
|
||||||
use function preg_match;
|
use function preg_match;
|
||||||
use function str_replace;
|
use function str_replace;
|
||||||
use function stripos;
|
use function stripos;
|
||||||
use function strlen;
|
|
||||||
use function substr;
|
|
||||||
use function version_compare;
|
|
||||||
use function yaml_parse;
|
use function yaml_parse;
|
||||||
|
|
||||||
class PluginDescription{
|
class PluginDescription{
|
||||||
@ -247,40 +243,6 @@ class PluginDescription{
|
|||||||
return $this->extensions;
|
return $this->extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the current PHP runtime has the extensions required by the plugin.
|
|
||||||
*
|
|
||||||
* @throws PluginException if there are required extensions missing or have incompatible version, or if the version constraint cannot be parsed
|
|
||||||
*/
|
|
||||||
public function checkRequiredExtensions() : void{
|
|
||||||
foreach($this->extensions as $name => $versionConstrs){
|
|
||||||
$gotVersion = phpversion($name);
|
|
||||||
if($gotVersion === false){
|
|
||||||
throw new PluginException("Required extension $name not loaded");
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($versionConstrs as $constr){ // versionConstrs_loop
|
|
||||||
if($constr === "*"){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if($constr === ""){
|
|
||||||
throw new PluginException("One of the extension version constraints of $name is empty. Consider quoting the version string in plugin.yml");
|
|
||||||
}
|
|
||||||
foreach(["<=", "le", "<>", "!=", "ne", "<", "lt", "==", "=", "eq", ">=", "ge", ">", "gt"] as $comparator){
|
|
||||||
// warning: the > character should be quoted in YAML
|
|
||||||
if(substr($constr, 0, strlen($comparator)) === $comparator){
|
|
||||||
$version = substr($constr, strlen($comparator));
|
|
||||||
if(!version_compare($gotVersion, $version, $comparator)){
|
|
||||||
throw new PluginException("Required extension $name has an incompatible version ($gotVersion not $constr)");
|
|
||||||
}
|
|
||||||
continue 2; // versionConstrs_loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new PluginException("Error parsing version constraint: $constr");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
|
@ -64,12 +64,16 @@ use function is_string;
|
|||||||
use function is_subclass_of;
|
use function is_subclass_of;
|
||||||
use function iterator_to_array;
|
use function iterator_to_array;
|
||||||
use function mkdir;
|
use function mkdir;
|
||||||
|
use function phpversion;
|
||||||
use function realpath;
|
use function realpath;
|
||||||
use function shuffle;
|
use function shuffle;
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
use function stripos;
|
use function stripos;
|
||||||
|
use function strlen;
|
||||||
use function strpos;
|
use function strpos;
|
||||||
use function strtolower;
|
use function strtolower;
|
||||||
|
use function substr;
|
||||||
|
use function version_compare;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages all the plugins
|
* Manages all the plugins
|
||||||
@ -136,7 +140,7 @@ class PluginManager{
|
|||||||
return Path::join(dirname($pluginPath), $pluginName);
|
return Path::join(dirname($pluginPath), $pluginName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkPluginLoadability(PluginDescription $description) : Translatable|string|null{
|
private function checkPluginLoadability(PluginDescription $description) : Translatable|null{
|
||||||
$name = $description->getName();
|
$name = $description->getName();
|
||||||
if(stripos($name, "pocketmine") !== false or stripos($name, "minecraft") !== false or stripos($name, "mojang") !== false){
|
if(stripos($name, "pocketmine") !== false or stripos($name, "minecraft") !== false or stripos($name, "mojang") !== false){
|
||||||
return KnownTranslationFactory::pocketmine_plugin_restrictedName();
|
return KnownTranslationFactory::pocketmine_plugin_restrictedName();
|
||||||
@ -168,10 +172,31 @@ class PluginManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
foreach($description->getRequiredExtensions() as $extensionName => $versionConstrs){
|
||||||
$description->checkRequiredExtensions();
|
$gotVersion = phpversion($extensionName);
|
||||||
}catch(PluginException $ex){
|
if($gotVersion === false){
|
||||||
return $ex->getMessage();
|
return KnownTranslationFactory::pocketmine_plugin_extensionNotLoaded($extensionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($versionConstrs as $k => $constr){ // versionConstrs_loop
|
||||||
|
if($constr === "*"){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if($constr === ""){
|
||||||
|
return KnownTranslationFactory::pocketmine_plugin_emptyExtensionVersionConstraint(extensionName: $extensionName, constraintIndex: "$k");
|
||||||
|
}
|
||||||
|
foreach(["<=", "le", "<>", "!=", "ne", "<", "lt", "==", "=", "eq", ">=", "ge", ">", "gt"] as $comparator){
|
||||||
|
// warning: the > character should be quoted in YAML
|
||||||
|
if(substr($constr, 0, strlen($comparator)) === $comparator){
|
||||||
|
$version = substr($constr, strlen($comparator));
|
||||||
|
if(!version_compare($gotVersion, $version, $comparator)){
|
||||||
|
return KnownTranslationFactory::pocketmine_plugin_incompatibleExtensionVersion(extensionName: $extensionName, extensionVersion: $gotVersion, pluginRequirement: $constr);
|
||||||
|
}
|
||||||
|
continue 2; // versionConstrs_loop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return KnownTranslationFactory::pocketmine_plugin_invalidExtensionVersionConstraint(extensionName: $extensionName, versionConstraint: $constr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user