如何使用Composer安装没有版本的软件包(仅限主软件)

mah*_*n3d 16 composer-php

我是作曲家的新手,我试图通过作曲家更新安装此lib

https://github.com/neitanod/forceutf8
Run Code Online (Sandbox Code Playgroud)

所以我理解我的composer.json看起来像这样

{
    "config": {
        "vendor-dir": "libs/vendor"
    },
    "require": {
        "raven/raven": "0.7.1",
        "monolog/monolog": "1.7.*",
        "smarty/smarty": "3.1.16",
        "forceutf8/forceutf8": "master"
    }
}
Run Code Online (Sandbox Code Playgroud)

Bt由于某种原因(因为我认为forceutf8没有版本)它的停止有错误,所有其余安装正确,错误我得到的是

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
    - The requested package forceutf8/forceutf8 could not be found in any version, there may be a typo in the package na
me.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems. 
Run Code Online (Sandbox Code Playgroud)

我也尝试了以下版本,但仍然没有运气

{
    "config": {
        "vendor-dir": "libs/vendor"
    },
    "name": "career/skillquest",
    "repositories": [
      {
        "type": "vcs",
        "url": "https://github.com/neitanod/forceutf8"
      }
    ],
    "require": 
      {
        "forceutf8/forceutf8": "dev-master",
        "raven/raven": "0.7.1",
        "monolog/monolog": "1.7.*",
        "smarty/smarty": "3.1.16"
      }
}
Run Code Online (Sandbox Code Playgroud)

问题是它需要

"neitanod/forceutf8": "dev-master"
Run Code Online (Sandbox Code Playgroud)

"forceutf8/forceutf8": "master"
Run Code Online (Sandbox Code Playgroud)

Sve*_*ven 20

首先,你的名字错了:forceutf8/forceutf8正确的名字是:neitanod/forceutf8

Composer为每个不像版本号的分支名称添加前缀"dev-",并为分支名称添加后缀"-dev",看起来像版本号.

示例:分支"master"称为"dev-master",分支"feature"称为"dev-feature".分支"1.0.x"称为"1.0.x-dev".

所以这部分是错误的:

"require": {
    "raven/raven": "0.7.1",
    "monolog/monolog": "1.7.*",
    "smarty/smarty": "3.1.16",
    "forceutf8/forceutf8": "master"
}
Run Code Online (Sandbox Code Playgroud)

正确的版本将是:

"require": {
    "raven/raven": "0.7.1",
    "monolog/monolog": "1.7.*",
    "smarty/smarty": "3.1.16",
    "neitanod/forceutf8": "dev-master"
}
Run Code Online (Sandbox Code Playgroud)

现在需要没有标记版本的分支并不是最好的事情,因为这些信息非常不稳定 - 任何新的提交都可能会破坏事情,并且要完全指向您想要使用的提交并不容易.为了再次保护您,Composer默认情况下不会加载这些开发分支,而只会加载稳定版本.您必须启用加载开发版本:

"require": {
    "raven/raven": "0.7.1",
    "monolog/monolog": "1.7.*",
    "smarty/smarty": "3.1.16",
    "neitanod/forceutf8": "dev-master@dev"
}
Run Code Online (Sandbox Code Playgroud)

"@dev"标志允许加载所提及版本的开发版本(在本例中是一个分支,但"1.0.0@dev"将以相同的方式工作,允许所有(包括开发)版本的1.0.0,像"1.0.0-alpha",但也稳定的"1.0.0").

请注意,您还可以通过使用"minimum-stability"允许所有依赖项的开发版本,但不建议这样做,因为它将根据版本要求加载一切的开发版本.在你的情况下,你只会获取monolog的1.7分支的最新开发版本,但这可能足以使曾经稳定的软件进入破坏状态.

  • 非常感谢您的解释:“ Composer在每个看起来不像版本号的分支名称上都添加了前缀“ dev-”,并在看起来像版本号的分支名称中添加了后缀“ -dev”。我在Composer中鄙视此语法。 (2认同)

Ale*_*r T 19

composer.json中:

{
    "name": "example/example-app",
    "repositories": [
      {
        "type": "vcs",
        "url": "https://github.com/neitanod/forceutf8"
      }
    ],
    "require": 
      {
        "neitanod/forceutf8": "dev-master",
        "raven/raven": "0.7.1",
        "monolog/monolog": "1.7.*",
        "smarty/smarty": "3.1.16"
      }
}
Run Code Online (Sandbox Code Playgroud)


Raf*_*ier 6

这很简单!您应该在控制台上输入:

composer require blablabla@thepackage dev-master
Run Code Online (Sandbox Code Playgroud)