Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a package with Composer (through SVN)

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

like image 615
Nabab Avatar asked Dec 30 '12 19:12

Nabab


People also ask

How do I add a repository to composer?

You can add more repositories to your project by declaring them in composer. json . Repositories are only available to the root package and the repositories defined in your dependencies will not be loaded.

What is a composer package?

Composer is an application-level dependency manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries. It was developed by Nils Adermann and Jordi Boggiano, who continue to manage the project.


2 Answers

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.

like image 180
Marián Černý Avatar answered Sep 25 '22 01:09

Marián Černý


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)
like image 22
SimonSimCity Avatar answered Sep 24 '22 01:09

SimonSimCity