我应该在哪里放置composer.json文件?

时间:2018-05-27 05:56:46

标签: composer-php

我正在尝试将composer用于库,并且在文档中他们告诉我在composer.json文件(require : xxxx)中添加一行,但已经有{{1}文件中存在的文件。

我试过阅读有关作曲家的文档,他们说要将文件放在主文件夹中。但是已经存在一个composer.json文件。

当我输入composer.json我需要的内容(require)时,我收到此错误(我使用命令setasign/fpdi-fpdf": "^2.0得到了同样的错误):

composer require setasign/fpdi-fpdf

我对作曲家并不熟悉,但我不知道如何处理这个错误。

我的composer require setasign/fpdi-fpdf Using version ^2.0 for setasign/fpdi-fpdf ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for setasign/fpdi No version set (parsed as 1.0.0) -> satisfiable by setasign/fpdi[No version set (parsed as 1.0.0)]. - setasign/fpdi-fpdf v2.0.0 requires setasign/fpdi ^2.0 -> satisfiable by setasign/fpdi[v2.0.0, v2.0.1, v2.0.2, v2.0.3]. - Can only install one of: setasign/fpdi[v2.0.0, No version set (parsed as 1.0.0)]. - Can only install one of: setasign/fpdi[v2.0.1, No version set (parsed as 1.0.0)]. - Can only install one of: setasign/fpdi[v2.0.2, No version set (parsed as 1.0.0)]. - Can only install one of: setasign/fpdi[v2.0.3, No version set (parsed as 1.0.0)]. - Installation request for setasign/fpdi-fpdf ^2.0 -> satisfiable by setasign/fpdi-fpdf[v2.0.0]. Installation failed, reverting ./composer.json to its original content. 文件如下所示:

composer.json

我也在图书馆问题上寻求帮助,有人回答我:

  

为什么使用FPDI的composer.json?   当然,您需要创建自己的:https://getcomposer.org/doc/01-basic-usage.md

这就是为什么我没有真正得到它。 (之后他没有回答我,这就是为什么我在这里)。

我应该覆盖现有的{ "name": "setasign/fpdi", "homepage": "https://www.setasign.com/fpdi", "description": "FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates in FPDF. Because it is also possible to use FPDI with TCPDF, there are no fixed dependencies defined. Please see suggestions for packages which evaluates the dependencies automatically.", "type": "library", "keywords": [ "pdf", "fpdi", "fpdf" ], "license": "MIT", "autoload": { "psr-4": { "setasign\\Fpdi\\": "src/" } }, "require": { "php": "^5.6 || ^7.0", "ext-zlib": "*"}, "authors": [ { "name": "Jan Slabon", "email": "jan.slabon@setasign.com", "homepage": "https://www.setasign.com" }, { "name": "Maximilian Kresse", "email": "maximilian.kresse@setasign.com", "homepage": "https://www.setasign.com" } ], "suggest": { "setasign/fpdf": "FPDI will extend this class but as it is also possible to use \"tecnickcom/tcpdf\" as an alternative there's no fixed dependency configured.", "setasign/fpdi-fpdf": "Use this package to automatically evaluate dependencies to FPDF.", "setasign/fpdi-tcpdf": "Use this package to automatically evaluate dependencies to TCPDF." }, "require-dev": { "phpunit/phpunit": "~5.7", "setasign/fpdf": "~1.8", "tecnickcom/tcpdf": "~6.2" }, "autoload-dev": { "psr-4": { "setasign\\Fpdi\\": "tests/" } } } 文件吗? 或者我应该把文件放在另一个地方?

2 个答案:

答案 0 :(得分:2)

您的项目中应该有一个 composer.json文件,您应该在其中添加新的依赖项。但不是在随机的地方,它应该在require部分内。

因此,如果您的旧composer.json看起来像:

{
    "require": {
        "some-old/dependency": "1.0.*"
    }
}

添加新依赖项后,它应如下所示:

{
    "require": {
        "some-old/dependency": "1.0.*",
        "new/dependency": "^1.6"
    }
}

^1.6对于您要安装的依赖项版本为constraint

如果您不知道如何编辑composer.json,可以使用composer命令执行此任务:

composer require new/dependency

它会自动为您的composer.json添加相关性并进行安装。它还会选择最新版本的依赖项的约束,所以这可能是你想要的最简单的方法。

答案 1 :(得分:0)

这个问题根本不复杂,我只是不知道我必须将依赖项放在我自己的composer.json文件中,而不是库中的文件夹。

感谢Rob的有用帮助。