Composer: how to add dependency without network connection?
My professional internet web access. A few months ago, I download the Silex framework from the archive (which contains the composer.json file) and composer.phar, and then I transfer them to my desktop via the hard drive.
My composer .json that I configured:
{
"name": "user/silex",
"require": {
"silex/silex": "1.2"
, "twig/twig": ">=1.8,<2.0-dev"
, "doctrine/dbal": "2.2.*"
, "symfony/security": "~2.3"
, "symfony/security": "~2.3"
},
"autoload": {
"psr-4": {
"Portal\\": "src/"
}
}
}
It works great, my autoload setting does too.
Today I want to add a package monolog/monolog
, so I manually import it from another computer.
I put it in my vendor folder, add the following line to my composer.json file:
, "monolog/monolog": ">=1.0.0"
I launch the console:
php composer.phar dumpautoload
It outputs: Create startup files
Then it stops without error, but the monolog namespace doesn't show up in my files /vendor/composer/autoload_*.php
.
What did I miss?
source to share
Thanks to the comment from edmondscommerce I found a solution:
I am updating my main composer.json file with the repository artifact (and I will disable the batch)
{
"name": "user/silex",
"repositories": [
{
"type": "artifact",
"url": "artifact/"
}, {
"packagist": false
}
], "require": {
"silex/silex": "1.2"
, "twig/twig": ">=1.8,<2.0-dev"
, "monolog/monolog": "1.*"
, "doctrine/dbal": "2.2.*"
, "symfony/security": "~2.3"
},
"autoload": {
"psr-4": {
"Portal\\": "src/"
}
}
}
Then I put the folder named artifact
according to the url placed in the composer.json file.
I create a zip in this folder called monolog-monolog-1.8.zip with the library I want to add.
Then just run the command composer update
!
Be careful, the zip root must contain the composer.json file and that composer.json file must contain the version!
source to share
If you don't want to create a custom repository, you can also run composer install
(or composer update
) a copy connected to a computer connected to the network. You can then copy over the newly added and extracted component to the vendor folder on a computer without Internet access. Note that you also need to copy vendor/composer/installed.json
so the composer knows the new package is installed. Once you've copied all these files, you can run composer install
on the machine without internet access and it won't try to install anything and reset the startup files.
source to share