0

是否可以通过 \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>
4

1 回答 1

0

您是否尝试过命令exec("php composer.phar update") exec 描述

讨论后更新:
代码的答案composer.phar/src/Composer/Command/StatusCommand.php [lines 43-92]- 它可用于检查存储库的更新

于 2013-10-10T11:55:10.043 回答