Skip to content

Commit

Permalink
Add get_composer_packages command (#32)
Browse files Browse the repository at this point in the history
Co-authored-by: yunbaoi <[email protected]>
Co-authored-by: yun <[email protected]>
Co-committed-by: yun <[email protected]>
  • Loading branch information
yunbaoi authored and lufei committed Oct 18, 2021
1 parent 8ed52a6 commit 07763f4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/core/Server/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 07763f4

Please sign in to comment.