douhao5280 2017-03-14 09:12
浏览 160
已采纳

在composer中指定项目根目录之外的依赖项

I have a directory of projects. Each of these is from a git repo.

Some of these projects are REST APIs, and I want everything specified as a project dependency, like this:

htdocs
|- restApi1
|- restApi2
    |- Vendor
        |-Guzzle
|- restApi3

So project 2 has a dependency on restApi1 and restApi3. What I want to do is 'git checkout' if restApi1 or restApi3 is missing when I install restApi2 and build. If it is already checked out, upon composer install or update, I want it to git pull and rebuild to a custom command, that's it. Since I have these setup as projects and I might be working on a change across two projects, if I pull as a dependency in like this:

htdocs
|- restApi1
|- restApi2
    |- Vendor
        |- Guzzle
        |- restApi1
        |- restApi3
|- restApi3

I have to do work to pull my changes into their repo, work to new URLs and it disrupts my workflow. Since I hit the projects through http on localhost, I can check out whatever version from wherever and treat everything as if it were one big project of sorts, where all my codebases appear once.

Im wondering if there is a way to do this in composer, or if this is the wrong way to go about it. Im also willing to switch my flow if theres a better way that conflicts the above. Ive considered writing a script to run on htdocs that rifles through and pulls everything, but I think specifying other projects as a dependency in the composer file reveals more info about how our internal prohjects use each other.

  • 写回答

1条回答 默认 最新

  • dragon2025 2017-03-14 15:37
    关注

    You can add restApi1 and restApi3 to you composer.json:

    "require" : {
        ...
        "myproject/restApi1": "dev-master",
        "myproject/restApi3": "dev-master"
    },
    "repositories": {
        "myproject/restApi1": {
            "url": "https://github.com/myproject/restApi1.git",
            "type":"git"
        },
        "myproject/restApi3": {
            "url": "https://github.com/myproject/restApi3.git",
            "type":"git"
        },
    }
    

    Then composer update each time yo want new updates.

    The other option is to use git submodules.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?