使用 PHP composer 克隆 git repo

2022-01-21 00:00:00 php composer-php packagist

我正在尝试使用 composer 从 github 自动克隆一个不在 packagist 但它不起作用,我不知道我做错了什么.

I'm trying to use composer to automatically clone a git repository from github that isn't in packagist but it's not working and I can't figure out what am I doing wrong.

我认为我必须像这样将它包含在存储库"中:

I think I have to include it among "repositories" like so:

"repositories": [
    {
        "url": "https://github.com/l3pp4rd/DoctrineExtensions.git",
        "type": "git"
    }
],

然后可能将其列在要求"部分.它应该类似于 this example 但它不起作用.它只是给出了这个错误:

and then probably list it in "require" section. It should be similar to this example but it doesn't work. It just gives this error:

您的需求无法解决为一组可安装的软件包.

Your requirements could not be resolved to an installable set of packages.

有没有人尝试过这样做?

Have anyone tried to do something like this already?

推荐答案

在 2013 年撰写本文时,这是一种方法.Composer 添加了对更好方法的支持:请参阅 @igorw 的 answer

At the time of writing in 2013, this was one way to do it. Composer has added support for better ways: See @igorw 's answer

您有存储库吗?

Composer 支持 Git、Mercurial 和 SVN.

Git, Mercurial and SVN is supported by Composer.

您对存储库有写入权限吗?

是吗?

存储库是否有 composer.json 文件

DOES THE REPOSITORY HAVE A composer.json FILE

如果您有可以写入的存储库:添加 composer.json 文件,或修复现有文件,不要使用以下解决方案.

If you have a repository you can write to: Add a composer.json file, or fix the existing one, and DON'T use the solution below.

转到@igorw 的答案

只有在您没有存储库时才使用它
或者如果存储库没有 composer.json 并且您无法添加它

ONLY USE THIS IF YOU DON'T HAVE A REPOSITORY
OR IF THE REPOSITORY DOES NOT HAVE A composer.json AND YOU CANNOT ADD IT

这将覆盖 Composer 可能能够从原始存储库的 composer.json 读取的所有内容,包括包的依赖项和自动加载.

This will override everything that Composer may be able to read from the original repository's composer.json, including the dependencies of the package and the autoloading.

使用 package 类型会将正确定义所有内容的负担转移到您身上.更简单的方法是在存储库中有一个 composer.json 文件,然后直接使用它.

Using the package type will transfer the burden of correctly defining everything onto you. The easier way is to have a composer.json file in the repository, and just use it.

此解决方案实际上仅适用于您无法更改的废弃 ZIP 下载文件或您只能读取但不再维护的存储库的极少数情况.

This solution really only is for the rare cases where you have an abandoned ZIP download that you cannot alter, or a repository you can only read, but it isn't maintained anymore.

"repositories": [
    {
        "type":"package",
        "package": {
          "name": "l3pp4rd/doctrine-extensions",
          "version":"master",
          "source": {
              "url": "https://github.com/l3pp4rd/DoctrineExtensions.git",
              "type": "git",
              "reference":"master"
            }
        }
    }
],
"require": {
    "l3pp4rd/doctrine-extensions": "master"
}

相关文章