是否可以从应用程序代码中调用作曲家更新,通过 \Composer\ 命名空间进行试运行以获取有关 udpates 的信息?
我在谷歌上搜索过,只找到了关于作曲家插件或编写(post|pre(-(install|update(钩子脚本的信息,但没有找到任何关于获取此类信息的信息。
解决:将自定义作曲家脚本放入pre-update-cmd
:
<?php namespace MyNamespace; use ComposerScriptEvent; use ComposerPluginCommandEvent; use ComposerPluginPluginEvents; 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>
您是否尝试过命令exec("php composer.phar update")
执行描述?
讨论后更新:
关于代码composer.phar/src/Composer/Command/StatusCommand.php [lines 43-92]
的答案 - 它可用于检查存储库的更新