From 34cb8b142089e6997631a5b549174438e8dcc79b Mon Sep 17 00:00:00 2001 From: Death-Satan <49744633+Death-Satan@users.noreply.github.com> Date: Wed, 13 Mar 2024 11:41:21 +0800 Subject: [PATCH] Add plugin-to-plugin dependency checking --- src/app-store/src/Plugin.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/app-store/src/Plugin.php b/src/app-store/src/Plugin.php index f17e2063..154fea7d 100644 --- a/src/app-store/src/Plugin.php +++ b/src/app-store/src/Plugin.php @@ -127,6 +127,21 @@ public static function read(string $path) return null; } + /** + * Detects if the given plugin exists and is installed. + */ + public static function exists(string $name): bool + { + $jsonPaths = self::getPluginJsonPaths(); + foreach ($jsonPaths as $jsonPath) { + $info = self::read($jsonPath->getRelativePath()); + if ($info['name'] === $name) { + return true; + } + } + return false; + } + /** * Install the plugin according to the given directory. */ @@ -140,6 +155,24 @@ public static function install(string $path): void probably because it is already installed or the directory is not standardized' ); } + // Performs a check on plugin dependencies. Determine if the plugin also depends on other plugins + if (! empty($info['require'])) { + if (! is_array($info['require'])) { + throw new \RuntimeException('Plugin dependency format error'); + } + $pluginRequires = $info['require']; + foreach ($pluginRequires as $require) { + if (! self::exists($require)) { + throw new \RuntimeException( + sprintf( + 'Plugin %s depends on plugin %s, but the dependency is not installed', + $info['name'], + $require + ) + ); + } + } + } // Handling composer dependencies if (! empty($info['composer']['require'])) { $requires = $info['composer']['require'];