如何在没有网络连接的情况下添加依赖项

如何在没有网络连接的情况下添加依赖项

本文介绍了Composer:如何在没有网络连接的情况下添加依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的专业网络阻止了Internet访问.一个月前,我从存档文件(包含composer.json文件)和composer.phar文件中下载了Silex框架,然后将它们通过HDD传输到了桌面上.

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.

我自定义的composer.json:

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.

今天,我想添加 monolog/monolog 包,因此我需要从另一台计算机上手动导入它.

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

我将其放置在我的供应商文件夹中,将以下行添加到我的composer.json文件中:

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

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

我在控制台上运行:

php composer.phar dumpautoload

它输出:生成自动加载文件

It outputs: Generating autoload files

然后它立即停止运行,但没有错误,但是monolog命名空间没有出现在我的/vendor/composer/autoload _ *.php 文件中.

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

我想念什么?

推荐答案

感谢 edmondscommerce 的评论,我发现解决方案:

Thanks to edmondscommerce's comment I found the solution:

我使用更新我的主要 composer.json 文件.工件 存储库(并且我禁用了包装专家):

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/"
        }
    }
}

然后我根据 composer.json 文件中放置的URL放置一个名为 artifact 的文件夹.

Then I put a folder called artifact according to the url put in the composer.json file.

我在这个文件夹中创建一个名为 monolog-monolog-1.8.zip 的zip文件,其中包含我要添加的库.

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

然后只需启动 composer update 命令!

请注意,zip的根目录必须包含一个 composer.json 文件,并且此 composer.json 文件必须包含一个版本!

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

这篇关于Composer:如何在没有网络连接的情况下添加依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 13:15