henning glatter-götz

PHP Composer: Working with local repositories

When developing packages or Bundles for your Symfony2 project it is nice to be able to manage them in their own repository and have Composer deal with installing them in your test project. This is a bit slow and quite cumbersome if you are using something like GitHub since you have to push changes to remote and then Composer has to pull it all back down.

To make this a bit more convenient it is possible to configure your project to use a package from a local git repository:

In composer.json:

1
2
3
4
5
6
7
8
9
10
11
12
:
"repositories": [
    {
        "type": "vcs",
        "url": "/path/to/the/local/git/repository"
    }
],
"require": {
    :
    "username/package-name": "dev-master"
},
:

Here username/package-name is the value that is specified under the “name” key in the composer.json of the package.

So the work flow would be as follows:

  • Work on Bundle and commit to its repository locally
  • In your Symfony2 project execute composer update username/package-name

This also lets you use a git repo hosted on GitHub that is not registered on packagist.org

1
2
3
4
5
6
7
8
:
"repositories": [
    {
        "type": "vcs",
        "url": "http://github.com/username/reponame"
    }
],
:

Comments