Reputation: 1284
I'm using composer to organize my vendor libraries. One of these libraries is a private repository of general system classes.
The problem is that I want to have my code run out of the dev branch when it's on the dev environment, and automatically use the dev branch of my composer library. When the code is on staging, I want to use the staging branch and have composer switch to use the staging branch of the composer library. Same for production.
Is it possible for composer to pull the correct branch without having to manually switch to that branch or edit the composer.json file?
Edit: useful answer is the comments of accepted answer.
Upvotes: 1
Views: 1574
Reputation: 70863
Composer is not designed to dynamically include code. In fact, it is designed to intentionally NOT change the code on it's own, but only with developer interaction (i.e. explicitly updating).
So if you manage to require one version in your dev branch, and then merge this to staging, if you move the composer.lock
unaltered, it will fetch exactly the version of your dev branch situation - now in staging. Which is actually a good thing because you do want to test the real software, and the software used to develop is the software that should go to staging and then to production - nothing else that is dynamically bound.
I am experiencing quite the same problem with an old legacy module. It does contain configuration data, which should get rolled out differently to dev, staging and production, but I cannot use Composer for this.
Maybe if you can describe your use case a bit more, there might be a solution for you. But I hardly believe it will contain Composer.
Upvotes: 1
Reputation: 9303
Branch aliases are great for aliasing main development lines. But in order to use them you need to have control over the source repository, and you need to commit changes to version control.
This is not really fun when you just want to try a bugfix of some library that is a dependency of your local project.
For this reason, you can alias packages in your require
and require-dev
fields. Let's say you found a bug in the monolog/monolog
package. You cloned Monolog on GitHub and fixed the issue in a branch named bugfix
. Now you want to install that version of monolog in your local project.
You are using symfony/monolog-bundle
which requires monolog/monolog
version 1.*
. So you need your dev-bugfix
to match that constraint.
Just add this to your project's root composer.json
:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/you/monolog"
}
],
"require": {
"symfony/monolog-bundle": "2.0",
"monolog/monolog": "dev-bugfix as 1.0.x-dev"
}
}
Upvotes: 0