Adding a package with Composer (through SVN)
Asked Answered
T

2

18

I created a SVN repository for my personal PHP library, and added a composer.json file at the root level:

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

Then I created a project with the following 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"
            }
    ]
}

And when I try to update my project I get: No valid composer.json was found in any branch or tag of https...

I think the problem is coming from my file's structure but I couldn't manage to find any documentation about this:

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

I tried to post my URL on packagist.org and got No valid/supported repository was found at the given URL

Timbale answered 30/12, 2012 at 19:31 Comment(16)
Shouldn't 'composer.json' be under /my_repo/src/ ?Connally
is the composer.json valid? no leftover commas or something?Iggy
Yes, I've checked it a few times, and if I do it with GIT it works fine (but I want to do it with SVN)Timbale
have you tried setting the type of the repository to vcs? composer should be auto detecting that it is svn. however that should not be the problem. further ideas: do you need any login to your svn repository? is the certificate correct? is the svn client accessible for your composer installation?Margo
@pptermann I guess this is automatically checked from packagist. The repo is accessible anounimously in read-only . The certificate is correct, and I tried with and without https. I am not sure I undesratnd your last questionTimbale
If the SVN repo is only accessible via https, there is currently an issue: github.com/composer/packagist/issues/255 - Could you perhaps give us the real URL of the repository? If you are trying to submit it on packagist anyway it can't be that secret.Paphlagonia
Ah I see. The composer.json should be in the trunk directory. And yes there must be a trunk/ for packagist. If you want branches and tags every tag and branch must also have its own composer.json. The reason is simply that every version is unique and can have different requirements/dependencies. Having just one file at the root of the repository wouldn't work for long.Paphlagonia
Thanks, but you've seen how the second svn has a trunk and a composer.json in it? That's not how it should be?Timbale
Is the autoload part correct? bbn does not look like a valid namespace...Olivette
@jamie0726 Maybe it was not I don't know, I have moved to Github like everyone, but I would rather have this working on my own svn one of these days. Why do you say the namespace is not valid?Timbale
@Timbale I watched this video on Composer from Symfony Live 12 in SF recently. Very helpful tips (e.g. he explains how to have your own private packagist.com): symfony.com/video/26/in-depth-with-composer/EnglishOlivette
@jamie0726 Thanks, I'll watch it.Timbale
Shouldn't the repo type be VCS? getcomposer.org/doc/05-repositories.md#subversion-optionsSemiramis
@sinkingfish, per the docs: "should you need to specify one for whatever reason, you can use git, svn or hg as the repository type instead of vcs"Ipomoea
Have you tried to update composer (never know ...) using composer self-update?Aile
@Thierry, I have done it for the first time a few days ago, but I haven't retried to put my code on my own SVN since then (I had put the repo on GitHub to solve the problem), but I'll retry at some stage. ThanksTimbale
I
13

If you use the officially recommended repository layout with a "project root" (which contains exactly three subdirectories: /trunk, /branches, and /tags) then this should work for you:

For your PHP library create composer.json in project root in the trunk (and commit it). For example:

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

Lets say your library repository is available at http://svn.example.com/path/to/myLibrary. The layout then would be:

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

Then in you project, where you want to use your library, create composer.json with the following contents:

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

The key is to use @dev as the required version for your library if you only have composer.json in trunk yet. Once you create a tag from trunk, you can start using version numbers. For example if you svn copy ^/trunk ^/tags/1.0.0, then you can use "myProject/myLibrary": "~1.0" as your version number.

Indestructible answered 23/7, 2014 at 18:41 Comment(0)
M
3

Try to get more information calling composer update -v to get a list of possible version strings you can use.

I for example got the info, that the correct name for fetching the trunk was this config:

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

Calling composer with -v as argument, you'll get a list of branches, tags and the trunk, if found. I don't know if false is allowed as path for tags and branches ...

$ 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)

You can safely ignore all excepted by this line, which tells you what you have to set as requested version:

Importing branch trunk (dev-trunk)
Mccleary answered 17/4, 2013 at 16:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.