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

2022-08-30 22:23:21

我为我的个人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 上发布我的URL,并得到了No valid/supported repository was found at the given URL


答案 1

如果您将官方推荐的存储库布局与“项目根目录”(正好包含三个子目录:、、和)一起使用,那么这应该适合您:/trunk/branches/tags

对于您的PHP库,在主干中的项目根目录中创建(并提交它)。例如:composer.json

{
    "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"
    }
}

关键是要用作库的必需版本(如果您只在主干中)。从主干创建标记后,即可开始使用版本号。例如,如果您 ,则可以用作您的版本号。@devcomposer.jsonsvn copy ^/trunk ^/tags/1.0.0"myProject/myLibrary": "~1.0"


答案 2

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

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

{
    "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 作为参数调用 composer,如果找到,您将获得分支、标记和主干的列表。我不知道是否允许将 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)

推荐