18

我为我的个人 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

4

2 回答 2

13

如果您将官方推荐的存储库布局与“项目根目录”(其中包含三个子目录:/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"
    }
}

@dev如果您只有composer.json主干,关键是用作您的图书馆所需的版本。从主干创建标签后,您可以开始使用版本号。例如,如果你svn copy ^/trunk ^/tags/1.0.0,那么你可以使用"myProject/myLibrary": "~1.0"你的版本号。

于 2014-07-23T18:41:53.077 回答
3

尝试调用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)
于 2013-04-17T16:52:33.967 回答