是否可以通过 \Composer\ 命名空间从应用程序代码中调用 composer update 以获取有关 udpates 的信息?
我在 google 中搜索过,仅找到有关 Composer 插件或编写 (post|pre)-(install|update) 挂钩脚本的信息,但没有找到任何有关获取此类信息的信息。
已解决:将自定义作曲家脚本放入pre-update-cmd
:
<?php
namespace MyNamespace;
use Composer\Script\Event;
use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents;
class CheckStatus
{
public static function preUpdate(Event $event)
{
/* get composer */
$composer = $event->getComposer();
$installedRepo = $composer->getRepositoryManager()->getLocalRepository();
$dm = $composer->getDownloadManager();
$im = $composer->getInstallationManager();
$errors = array();
/* list packages */
foreach ($installedRepo->getPackages() as $package) {
$downloader = $dm->getDownloaderForInstalledPackage($package);
if ($downloader instanceof ChangeReportInterface) {
$targetDir = $im->getInstallPath($package);
if ($changes = $downloader->getLocalChanges($package, $targetDir)) {
$errors[$targetDir] = $changes;
}
}
}
if (!$errors) {
$status['changes'] = null;
} else {
$status['changes'] = $errors;
}
// in $status['changes'] we have all pending updates
}
}
</code>