dping1968 2015-04-01 17:18
浏览 258

Composer:优先于Packagist上的VCS存储库

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

  • 写回答

1条回答 默认 最新

  • dpbl91234 2015-04-01 17:57
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。