28

我有一个托管在 Bit Bucket 上的私人项目。我有一个 SSH 密钥设置。有没有办法可以php composer create-project vendor/name path像在 Packagist 上一样使用该命令?

4

5 回答 5

30

Well there are different ways to accomplish this one being the use of a composer repository that is used instead of packagist.org, which is a better more centralized way to manage your private composer packages. The other method is to use a composer.json that incorporates your private repos within your environments, per environment.

First

Composer allows you to use private repositories to create projects.

Like so...

composer create-project vendor/name path --repository-url=http://repo.yourcomposerrepo.com

Since you won't submit a private package to packagist. That url just needs a packages.json file at minimum, you could use satis or your own packagist if you want a more dynamic solution to the packages.json.

The method for using composer.json applies to already created projects that will use custom repositories for private packages, not for creating new projects from private repositories. Use the next method if you want to go down a similar route.

Second

Configure your private repository into your config.json globally for your environment. Then like normally..

composer create-project vendor/name path
于 2013-10-11T19:21:08.320 回答
17

是的,Composer 允许您将私有项目作为“存储库”添加到您的 composer.json 文件中。因此,您可以将私有项目包含到另一个项目中。

它为 GitHub 和 Bitbucket(以及 SVN 和 Mercurial)提供支持。

您需要修改您的 composer.json 文件,使其看起来像这样:

{
    "repositories": [ {
        "type": "package",
        "package": {
            "name": "TheShiftExchange/test",
            "version": "1.0.0",
            "source": {
                "url": "https://github.com/TheShiftExchange/test.git",
                "type": "git",
                "reference": "master"
              }
         }
    }],
    "require": {
        "laravel/framework": "4.0.*",
        "TheShiftExchange/test": "1.0.*"
    },
}
于 2013-08-10T11:52:32.230 回答
7

我以前的方式:

composer create-project vendor/name path --repository="{\"url\": \"https://bitbucket.org/user/project.git\", \"type\": \"vcs\"}" --stability=dev --remove-vcs

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

于 2019-10-02T09:45:51.943 回答
3

我们将 Toran Proxy ( https://toranproxy.com/ ) 安装为私有 packageagist,为此我们可以使用以下命令创建项目

composer create-project vendor/framework --repository-url=http://your-toran-repo-url/repo/private/ --stability=dev project name

如果项目未标记或您正在寻找最前沿的版本,我们使用的稳定性版本。

--stability=dev
于 2014-10-26T07:24:21.873 回答
1

由于这篇文章有一些吸引力,我想我会添加另一个我使用的解决方案。打开 ~/.bash_profile

并添加类似

function _cmsname {
    composer create-project vendor/package --repository-url=http://private.repo.url.co.uk/ --stability=dev "$1"
}
alias cmsname=_cmsname

并且只需输入cmsname projectname终端。

于 2016-01-29T09:47:36.017 回答