From 07763f4636fb4c41d2c2914a8ac4579355827b93 Mon Sep 17 00:00:00 2001 From: yun <52o@qq52o.me> Date: Mon, 18 Oct 2021 00:55:16 +0000 Subject: [PATCH] Add get_composer_packages command (#32) Co-authored-by: yunbaoi <52o@qq52o.me> Co-authored-by: yun <52o@qq52o.me> Co-committed-by: yun <52o@qq52o.me> --- src/core/Server/Admin.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/core/Server/Admin.php b/src/core/Server/Admin.php index 7e609ce7..c7dd5449 100644 --- a/src/core/Server/Admin.php +++ b/src/core/Server/Admin.php @@ -348,6 +348,38 @@ function (Server $server, $msg) { ]); } ); + + $server->addCommand( + 'get_composer_packages', + $accepted_process_types, + function (Server $server, $msg) { + $list = []; + if (class_exists(\Composer\InstalledVersions::class)) { + foreach (['getAllRawData', 'getRawData'] as $method) { + if (method_exists(\Composer\InstalledVersions::class, $method)) { + if ($method === 'getAllRawData') { + $raw_data = \Composer\InstalledVersions::$method(); + array_shift($raw_data); + } else { + $raw_data[] = \Composer\InstalledVersions::$method(); + } + foreach ($raw_data as $key => $package) { + $key_name = $package['root']['name']; + if ($package['root']['name'] === '__root__' && isset($list['__root__'])) { + $key_name = "__root__{$key}"; + } + $package['root']['install_path'] = realpath($package['root']['install_path']); + $list[$key_name] = $package; + } + break; + } + } + } else { + return self::json('require composer 2.0', 4003); + } + return self::json($list); + } + ); } public static function start(Server $server)