LoginSignup
7
3

More than 5 years have passed since last update.

composer.jsonに"vendor/package": "dev-master as 1.1.1"のように書くと、バージョンを詐称できて便利だった。

Last updated at Posted at 2018-08-06

ComposerはPHPのパッケージ間のバージョンの互換性をしっかり管理してくれて、互換性に問題があれば報告してくれる。普段はありがたい安全装置だが、例えば次のような場面では不自由がある。

  • パッケージfoo/barは、4.6.3までリリースされている。
  • foo/bardev-masterにどうしても使いたい機能がある!
  • 別バッケージhoge/fugafoo/barに依存しており、バージョンは4.6系を必要としている。

そのため、foo/bardev-masterをインストールしようとすると、互換性の問題が報告されインストールできない:

$ composer require foo/bar=dev-master # 4.6.3からdev-masterにアップグレードしたい
  Problem 1
    - hoge/fuga 3.4 requires foo/bar ~4.6 -> satisfiable by foo/bar[4.6.0, 4.6.1, 4.6.2, 4.6.3] but these conflict with your requirements or minimum-stability.
    - hoge/fuga 3.4 requires foo/bar ~4.6 -> satisfiable by foo/bar[4.6.0, 4.6.1, 4.6.2, 4.6.3] but these conflict with your requirements or minimum-stability.
    - hoge/fuga 3.4 requires foo/bar ~4.6 -> satisfiable by foo/bar[4.6.0, 4.6.1, 4.6.2, 4.6.3] but these conflict with your requirements or minimum-stability.
    - Installation request for hoge/fuga ^3.4 -> satisfiable by hoge/fuga[3.4].

本来なら、互換が表明されていないバージョンを無理くり入れるのはリスクがあるので避けるべきだ。しかし、hoge/fugafoo/bardev-masterと事実上互換していることが明らかな場合はそのリスクがない。

以上のように、バージョンの互換性問題の報告を無視してでも、dev-masterを入れたいときには、"foo/bar": "dev-master as 4.6.4"のように書くと良い。これは、dev-masterに独自でバージョン「4.6.4」をつけるということだ。

{
  "require": {
    ...
    "foo/bar": "dev-master as 4.6.4",
    ...
  },
...

これで、foo/barのバージョンは、4.6.4に詐称できるため、4.6.xに依存するライブラリとの互換性の問題は報告されなくなる。

なお、次のようにdev-masterのコミットハッシュを指定することもできる。

{
  "require": {
    ...
    "foo/bar": "dev-master#a1b2c3d as 4.6.4",
    ...
  },
...

所感

7
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3