使用Composer添加软件包(通过SVN)?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (589)

我为我的个人PHP库创建了一个SVN仓库,并在根级别添加了一个composer.json文件:

{
        "name": "myPersonalLibrary/lib",
        "type": "library",
        "description": "Light MVC framework for PHP 5.4",
        "keywords": ["database","mvc"],
        "homepage": "http://mysite.com",
        "license": "MIT",
        "require": {
                "php": ">=5.3.0",
                "mustache/mustache": "dev-master"
        },
        "autoload": {
                "psr-0": {
                        "bbn": "src"
                }
        }
}

然后我用下面的composer.json创建了一个项目:

{
    "require": {
        "monolog/monolog": "1.0.*",
        "zerkalica/php-code-sniffer": "dev-master",
        "mustache/mustache": "dev-master",
        "myPersonalLibrary/lib": "*"
    },
    "repositories": [
            {
                    "type": "svn",
                    "url": "https://mysite.com/svn/myPersonalLibrary",
                    "branches-path": false,
                    "tags-path": false,
                    "trunk-path": "src"
            }
    ]
}

当我尝试更新我的项目时,我得到: No valid composer.json was found in any branch or tag of https...

我认为问题来自我的文件结构,但我无法找到任何有关此文档的文档:

/my_repo
  /src
    /lib
      /api
      /db
      /file
      /html
      ....
      /mvc.php
      /obj.php
  /composer.json

我试图在packagist.org上发布我的网址并获得 No valid/supported repository was found at the given URL

提问于
用户回答回答于

如果你有一个“项目根”(这恰好包含三个子目录:使用官方推荐的版本库布局/trunk/branches/tags),那么这应该为你工作:

为你的PHP库创建composer.json在trunk中的项目根目录(并提交它)。例如:

{
    "name": "myProject/myLibrary",
    "description": "My Personal Library",
    "license": "proprietary",
    "require": {
        "php": ">=5.3"
    },
    "autoload": {
        "classmap": ["src/"]
    }
}

可以说你的库存储库可以在http://svn.example.com/path/to/myLibrary。布局然后是:

/path/to/myLibrary
  /trunk
    /composer.json
    /src
      ...
  /branches
  /tags

然后在你想要使用你的库的项目中,使用以下内容创建composer.json:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "http://svn.example.com/path/to/myLibrary"
        }
    ],
    "require": {
        "nette/nette": "~2.2",
        "myProject/myLibrary": "@dev"
    }
}

@dev如果你只有composer.json中继线,关键是作为你的库需要的版本。一旦从中继创建标签,就可以开始使用版本号。例如,如果你svn copy ^/trunk ^/tags/1.0.0,那么你可以使用"myProject/myLibrary": "~1.0"你的版本号。

用户回答回答于

尝试获取更多信息,调用composer update -v以获取可以使用的可能版本字符串的列表。

例如,我得到了信息,提取trunk的正确名称是这个配置:

{
    "name": "sample/test",
    "type": "library",
    "version": "0.0.0",
    "time" : "2013-04-16",
    "description": "Testing ...",
    "repositories": [
        {
            "type": "svn",
            "url": "http://framework.zend.com/svn/framework/standard"
        }
    ],
    "require": {
        "php": ">=5.3.3",
        "zendframework/zendframework1" : "dev-trunk"
    }
}

使用-v作为参数调用作曲家,如果找到了分支,标签和树干列表,则会得到一个列表。我不知道是否允许false作为标签和分支的路径...

$ composer update -v
Loading composer repositories with package information
Reading composer.json of zendframework/zendframework1 (release-0.1.1)
Skipped tag 0.1.1, no composer file was found
Reading composer.json of zendframework/zendframework1 (release-0.1.2)
Skipped tag 0.1.2, no composer file was found
Reading composer.json of zendframework/zendframework1 (release-0.1.3)
Skipped tag 0.1.3, no composer file was found
....
Reading composer.json of zendframework/zendframework1 (release-1.9.6)
Importing tag 1.9.6 (1.9.6.0)
Reading composer.json of zendframework/zendframework1 (release-1.9.7)
Importing tag 1.9.7 (1.9.7.0)
Reading composer.json of zendframework/zendframework1 (release-1.9.8)
Importing tag 1.9.8 (1.9.8.0)
Reading composer.json of zendframework/zendframework1 (trunk)
Importing branch trunk (dev-trunk)
Reading composer.json of zendframework/zendframework1 (bughuntday)
Skipped branch bughuntday, no composer file was found
Reading composer.json of zendframework/zendframework1 (development-2.0)
Skipped branch development-2.0, no composer file was found
Reading composer.json of zendframework/zendframework1 (pdo_ibm_ids_support)
Skipped branch pdo_ibm_ids_support, no composer file was found
Reading composer.json of zendframework/zendframework1 (release-1.0)
Importing branch release-1.0 (dev-release-1.0)
Reading composer.json of zendframework/zendframework1 (release-1.10)
Importing branch release-1.10 (dev-release-1.10)
....
Reading composer.json of zendframework/zendframework1 (release-1.8)
Importing branch release-1.8 (dev-release-1.8)
Reading composer.json of zendframework/zendframework1 (release-1.9)
Importing branch release-1.9 (dev-release-1.9)
Reading composer.json of zendframework/zendframework1 (rob_allen)
Skipped branch rob_allen, no composer file was found
Reading composer.json of zendframework/zendframework1 (user)
Skipped branch user, no composer file was found
Updating dependencies (including require-dev)

你可以放心地忽略此行的所有内容,这将告诉你必须设置为所请求的版本:

Importing branch trunk (dev-trunk)

扫码关注云+社区

领取腾讯云代金券