Skip to content

Commit

Permalink
Revamp Plugin Manager (#501)
Browse files Browse the repository at this point in the history
Reworked the internal disabled status checking and monitoring system for plugins.
Added better support for plugin disabled status management.
Added improvements to loading (should aid in improving app bootup speed)
  • Loading branch information
LukeTowers authored Jun 3, 2022
1 parent 805b95b commit 1bbfb67
Show file tree
Hide file tree
Showing 11 changed files with 553 additions and 390 deletions.
29 changes: 24 additions & 5 deletions modules/system/classes/PluginBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ protected function getConfigurationFromYaml($exceptionMessage = null)
$this->loadedYamlConfiguration = [];
}
else {
$this->loadedYamlConfiguration = Yaml::parse(file_get_contents($yamlFilePath));
$this->loadedYamlConfiguration = Yaml::parseFile($yamlFilePath);
if (!is_array($this->loadedYamlConfiguration)) {
throw new SystemException(sprintf('Invalid format of the plugin configuration file: %s. The file should define an array.', $yamlFilePath));
}
Expand Down Expand Up @@ -404,8 +404,6 @@ public function getPluginIdentifier(): string

/**
* Returns the absolute path to this plugin's directory
*
* @return string
*/
public function getPluginPath(): string
{
Expand All @@ -414,7 +412,7 @@ public function getPluginPath(): string
}

$reflection = new ReflectionClass($this);
$this->path = dirname($reflection->getFileName());
$this->path = File::normalizePath(dirname($reflection->getFileName()));

return $this->path;
}
Expand All @@ -435,7 +433,7 @@ public function getPluginVersion(): string
if (
!File::isFile($versionFile)
|| !($versionInfo = Yaml::withProcessor(new VersionYamlProcessor, function ($yaml) use ($versionFile) {
return $yaml->parse(file_get_contents($versionFile));
return $yaml->parseFile($versionFile);
}))
|| !is_array($versionInfo)
) {
Expand All @@ -448,4 +446,25 @@ public function getPluginVersion(): string

return $this->version = trim(key(array_slice($versionInfo, -1, 1)));
}

/**
* Verifies the plugin's dependencies are present and enabled
*/
public function checkDependencies(PluginManager $manager): bool
{
$required = $manager->getDependencies($this);
if (empty($required)) {
return true;
}

foreach ($required as $require) {
$requiredPlugin = $manager->findByIdentifier($require);

if (!$requiredPlugin || $manager->isDisabled($requiredPlugin)) {
return false;
}
}

return true;
}
}
Loading

0 comments on commit 1bbfb67

Please sign in to comment.