Scenario:
I have an existing live site that loads in composer dependencies via several GIT repositories on dev-master
.
A new feature request comes in from the client and before I merge it from develop into master I need to deploy the new (unfinished) feature to a staging environment to get OK from the client before pushing live (I may need to show the client an early version of the new feature, not at all ready for master).
I usually deploy stuff via capistrano (not that it makes any difference I guess).
I can't use require-dev
for the new code as it's likely an existing plugin that needs to be refactored.
Ideally I'd be able to use dev-develop
for the plugin on the staging/development environment and dev-master
for the live environment, but it's not possible to have the same repository twice in the same composer.json file.
How can I accomplish this?
composer. json is a JSON file placed in the root folder of PHP project. Its purpose is to specify a common project properties, meta data and dependencies, and it is a part of vast array of existing projects. In most ways, it is a counterpart to . NET project file.
To configure Composer for your PHP app json file specifies required packages. Verify that a composer. json file is present in the root of your git repository. Run composer install (on your local machine) to install the required packages and generate a composer.
Classmap# The classmap references are all combined, during install/update, into a single key => value array which may be found in the generated file vendor/composer/autoload_classmap. php . This map is built by scanning for classes in all .
go to every package folder inside vendor folder and find the package's composer. json file. from that file find the "name" of that package from that composer.
The solution is to use environmental variables.
I have 2 composer.json
files (and also 2 composer.lock
files). The 2nd I named composer-dev.json
(this will subsequently generate a lock filed named composer-dev.lock
).
In my capistrano deploy config for the stage server I added
set :default_env, {
'COMPOSER' => 'composer-dev.json'
}
I can define the environmental variable on the fly on my local machine like so:
$ COMPOSER=composer-dev.json composer update
which generates the composer-dev.lock
file I can then deploy to the staging server.
Of course I could have configured the environment on the staging server, it just seems easier to do it in my capistrano config.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With