Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

php - Composer : how to add a dependency without network connection?

My profesionnal network block internet access. Some month ago I download the Silex framework from an archive (which contains composer.json file) and the composer.phar one's, then I transfer them on my desktop throught HDD.

My composer.json that I customized:

{
    "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 fine, my autoload customization too.

Today I want to add the monolog/monolog package, so I manually import it from an other computer.

I place it into my vendor folder, I add the following line to my composer.json file:

, "monolog/monolog": ">=1.0.0"

I run on the console:

php composer.phar dumpautoload

It outputs: Generating autoload files

Then it stop without error, but the monolog namespace doesn't appear into my /vendor/composer/autoload_*.php files.

What did I miss?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thanks to edmondscommerce's comment I found the solution:

I update my main composer.json file with an artifact respository (and I disable the packagist one):

{
    "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 a folder called artifact according to the url put in the composer.json file.

I create into this folder a zip called monolog-monolog-1.8.zip with the library I want to add.

Then just launch a composer update command!

Be carefull, zip's root must contain a composer.json file, and this composer.json file must contain a version!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...