php 作曲家:如何找到包的确切版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10684523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:48:18  来源:igfitidea点击:

composer: How to find the exact version of a package?

phpdependency-managementpackage-managerscomposer-php

提问by HappyDeveloper

Suppose I'm writing a library A, that depends on another library, monolog for instance.

假设我正在编写一个库 A,它依赖于另一个库,例如 monolog。

I want to install the latest version of monolog, so I just put this inside composer.json:

我想安装最新版本的 monolog,所以我把它放在 composer.json 中:

{
    "require": {
        "monolog/monolog": "*.*.*"
    }
}

Then I run $ php composer.phar install.

然后我跑$ php composer.phar install

I was expecting to find the version installed, inside composer.lock, but it's not there:

我期待在 composer.lock 中找到安装的版本,但它不在那里:

{
    "hash": "d7bcc4fe544b4ef7561918a8fc6ce009",
    "packages": [
        {
            "package": "monolog/monolog",
            "version": "dev-master",
            "source-reference": "2eb0c0978d290a1c45346a1955188929cb4e5db7"
        }
    ],
    "packages-dev": null,
    "aliases": [

    ],
    "minimum-stability": "dev",
    "stability-flags": [

    ]
}

I need the version because I want to tie my library to a specific set of versions, eg: If I find the version is 1.3.5, in my composer.json I would like to put something like this:

我需要版本,因为我想将我的库绑定到一组特定的版本,例如:如果我发现版本是 1.3.5,我想在我的 composer.json 中放置如下内容:

    "require": {
        "monolog/monolog": "1.3.*"
    }

Any ideas?

有任何想法吗?

回答by Ross Deane

I know it's an old question, but...

我知道这是一个老问题,但是......

composer.phar show

Will show all the currently installed packages and their version information. (This was shown in previous versions of Composer only when using the now-deprecated -ioption.)

将显示所有当前安装的软件包及其版本信息。(只有在使用现已弃用的-i选项时,才会在以前版本的 Composer 中显示这一点。)

To see more details, specify the name of the package as well:

要查看更多详细信息,请同时指定包的名称:

composer.phar show monolog/monolog

That will show many things, including commit MD5 hash, source URL, license type, etc.

这将显示许多内容,包括提交 MD5 哈希、源 URL、许可证类型等。

回答by Kévin Ferradj

You can use composer show like this:

您可以像这样使用作曲家表演:

composer show package/name

回答by Jimmix

If you're just interested to get the output as the package version number like: 1.7.5or 1.x-devor dev-master.

如果您只是想获得作为包版本号的输出,例如:1.7.51.x-devdev-master

Linux console snippet:

Linux 控制台片段:

composer show 'monolog/monolog' | grep 'versions' | grep -o -E '\*\ .+' | cut -d' ' -f2 | cut -d',' -f1;

回答by naderman

Technically "dev-master" is the exact version that you ended up using there. It is the development branch, and thus the very latest version.

从技术上讲,“dev-master”是您最终在那里使用的确切版本。它是开发分支,因此是最新版本。

The best place to look for available versions for composer packages is Packagistsince that's the place composer loads the versions from when you install packages. The monolog versions are listed on http://packagist.org/packages/monolog/monolog.

寻找Composer软件包可用版本的最佳位置是Packagist,因为这是Composer在您安装软件包时从中加载版本的地方。Monolog 版本在http://packagist.org/packages/monolog/monolog上列出。

回答by Mohsen

You can use show all, specially when dont have package.json file, get available packages from packagist.org:

你可以使用 show all,特别是当没有 package.json 文件时,从 packagist.org 获取可用的包:

composer show "monolog/monolog" --all

Also you can specify versions

您也可以指定版本

composer show "monolog/monolog" 1.* --all