325

我一直在我的本地机器上使用 Symfony 2.1 开发一个项目。我已经将它上传到我的服务器,但是当我尝试使用 Composer 安装供应商包时,我遇到了很多依赖错误。大概这与刚刚发布的最新版本的 Symfony 和我的composer.json文件没有指定确切的版本号有关。

有什么方法可以快速显示本地机器上所有内容的版本号?

这是我的 composer.json 文件(直到几天前还可以正常工作):

{
    "name": "symfony/framework-standard-edition",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.1.*",
        "doctrine/orm": ">=2.2.3,<2.4-dev",
        "doctrine/doctrine-bundle": "1.0.*",
        "twig/extensions": "1.0.*",
        "symfony/assetic-bundle": "2.1.*",
        "symfony/swiftmailer-bundle": "2.1.*",
        "symfony/monolog-bundle": "2.1.*",
        "sensio/distribution-bundle": "2.1.*",
        "sensio/framework-extra-bundle": "2.1.*",
        "sensio/generator-bundle": "2.1.*",
        "jms/security-extra-bundle": "1.2.*",
        "jms/di-extra-bundle": "1.1.*",
        "sonata-project/admin-bundle": "*",
        "sonata-project/cache-bundle": "dev-master",
        "sonata-project/doctrine-orm-admin-bundle": "dev-master",
        "stof/doctrine-extensions-bundle": "1.1.x-dev",
        "sonata-project/user-bundle": "dev-master",
        "sonata-project/easy-extends-bundle": "dev-master",
        "friendsofsymfony/user-bundle": "2.0.x-dev",
        "friendsofsymfony/jsrouting-bundle": "*",
        "liip/imagine-bundle": "*",
        "simplethings/form-extra-bundle": "dev-master",
        "antimattr/google-bundle": "dev-master",
        "doctrine/doctrine-fixtures-bundle": "dev-master",
        "genemu/form-bundle": "2.1.*",
        "behat/behat":                  "2.4.*@stable",
        "behat/mink":                   "1.4.*@stable",
        "behat/symfony2-extension":     "*@stable",
        "behat/mink-extension":         "*@stable",
        "behat/mink-selenium2-driver":  "*@stable",
        "behat/mink-browserkit-driver":  "*",
        "liip/functional-test-bundle": "dev-master"
    },
    "scripts": {
        "post-install-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ]
    },
    "minimum-stability": "dev",
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web"
    },
    "config": {
        "bin-dir": "bin/"
    }
}
4

9 回答 9

653

您可以运行composer show -i(的缩写--installed)。

在最新版本中,只需使用composer show.

这些-i选项已被弃用。

您还可以使用global作曲家的安装:composer global show

于 2013-03-03T13:29:21.050 回答
64

列出全局安装的作曲家包:

composer global show -i
于 2015-01-03T11:01:08.577 回答
27

列出已安装的依赖项:

  • 平坦的:composer show -i
  • 树:composer show -i -t

-i的缩写--installed

-t的缩写--tree

参考:https ://getcomposer.org/doc/03-cli.md#show

于 2016-04-12T08:24:32.213 回答
19

如果您只想检查一个版本,您可以这样做

composer show -- twig/twig

请注意,现在默认情况下仅显示已安装的软件包,并且已弃用已安装选项。

于 2016-06-18T12:47:34.193 回答
14

此命令的行为已修改,因此您不必传递-i选项:

[10:19:05] coil@coil:~/workspace/api$ composer show -i
You are using the deprecated option "installed". 
Only installed packages are shown by default now. 
The --all option can be used to show all packages.
于 2016-04-22T08:21:58.357 回答
6

上面伊万的回答很好:

composer global show -i

添加信息:如果您收到类似以下的消息:

Composer could not find a composer.json file in ~/.composer

...您可能还没有安装任何软件包。如果是这样,您可以忽略包含以下内容的消息的下一部分:

... please create a composer.json file ...

...因为一旦你安装了一个包,消息就会消失。

于 2015-05-09T18:31:19.917 回答
2

如果你想安装 Symfony2.2,你可以在你composer.json 的 Symfony 博客上看到完整的变化。

只需根据该更新您的文件并在composer update此之后运行。这将在您的项目中安装所有新的依赖项和 Symfony2.2。


如果您不想更新到 Symfony2.2,但有依赖错误,您应该发布这些,以便我们进一步帮助您。

于 2013-03-03T12:30:17.603 回答
2

使用 composer-runtime-api 2.0+ 有一个InstalledVersions带有一些静态方法的新类,可以以编程方式查看事物。

例如:

// To list all packages (`string[]`)
\Composer\InstalledVersions::getInstalledPackages();

// To list every details of every packages
\Composer\InstalledVersions::getAllRawData();

更多信息:https ://getcomposer.org/doc/07-runtime.md#installed-versions

于 2021-11-25T15:59:31.820 回答
1

有没有办法通过 $event->getComposer()->getRepositoryManager()->getAllPackages()

于 2020-06-20T19:17:38.990 回答