2

I'd like to use the adldap/adldap library in my PHP based project. While the maintainer of this package has not added this package to packagist, they have included a composer.json file. So, normally, I'd just add the following my MY composer.json, and go about my day.

"repositories": [
{
    "type": "vcs",
    "url": "https://github.com/adldap/adLDAP"
}], 

"require": {
    /* my other packages */
    "adldap/adldap":"4.04"
},

However, this won't work, because adldap/adldap is already claimed by a different project in packagist, and composer always assumes I want the packagist package. (Making things even more complicated, the packagist package is a fork of the original project, and a fork that isn't accepting upstream changes).

Is there a way to tell composer to prefer the version from the configured VCS repository? Or am I stuck forking the package myself, changing its name, and pointing composer to my fork? (or one of the other forks maintained to work around this very issue?)

Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • I'd say if the Packagist identifier does not point to the genuine article, that flouts the spirit of the system, if not the rules. Is there a way to notify the Packagist admins? Can you contact the fork maintainer to see if they'd be willing to change this? (I suppose it is now too late, if other people are relying on this identifier). – halfer Apr 01 '15 at 17:30
  • 2
    @halfer Seems like I'm not the only one to notice -- https://github.com/ztec/adLDAP/issues/5 I'll probably run it up the flag pole via twitter, but regardless of the spirit/rules, it'd be nice to know if there's a way to tell composer which package to prefer – Alana Storm Apr 01 '15 at 20:13
  • Good spot. I've added a note on that issue to draw attention to this question. – halfer Apr 01 '15 at 21:26

1 Answers1

5

The problem with this package is that, the "v4.0.4" version branch doesn't contain a composer.json file. That means that Composer can't pick it up and will skip this branch.

You could probably use an require inline alias to get this working. https://getcomposer.org/doc/articles/aliases.md#require-inline-alias

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/adldap/adLDAP"
        }
    ],
    "require": {
        "adldap/adldap": "dev-master as 4.0.4-dev"
    }
}

That will fetch the dev-master version of adldap/adldap from GitHub and alias it to 4.0.4-dev.

I don't know if this is a good way, maybe too hackish, but it will work.

In the future: they should include the composer.json file in their next release, so that you can get rid of the inline alias and require the normal version.


The example above uses the same repo, but a different branch for aliasing. The next example uses a different repo, with a reference branch (called patch). This repo/branch is used "instead" of the original package. The "reference branch" means you pick a branch from the forked repo and prefix it with "dev-". After a composer install, you should get the forked repo of adldap/adldap instead of the one from packagist.

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/repo-of-the-fork/adldap"
        }
    ],
    "require": {
        "adldap/adldap": "dev-patch"
    }
}

While this might resolve standalone, it may not resolve, when other packages rely on a specific version of adldap. To solve this, you can use the "inline alias" trick again: dev-patch as 4.0.4-dev.

Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
  • Useful, thank you! Was there a command you ran that made you realize that the 4.0.4 branch was missing a composer.json, or was it just instinct? – Alana Storm Apr 01 '15 at 20:10
  • I'm glad i could help! I used Composer in verbose mode: `composer install -vvv` – Jens A. Koch Apr 01 '15 at 20:18
  • Also, for other posted, I'm still interested in knowing if composer has a way to say "Use the version from this repository over that repository, when I tried using "*" as the version if went with the packagist version, which is what led to this question in the first place. – Alana Storm Apr 01 '15 at 20:28
  • I've appended my answer to address your question. (The version constraint "*" will not work. You have to specify the branch from the other repo, then you might alias it to a specifc version.) – Jens A. Koch Apr 01 '15 at 20:50
  • 1
    https://github.com/adldap/adLDAP/network - not sure, who will win this race, but the situation isn't nice. One maintainer should grab all the PRs integrate them and contact Jordi over at Packagist to replace the original packagist repo with the new maintained one. – Jens A. Koch Apr 01 '15 at 20:57