我只需要为我的SF2发行版安装一个包(DoctrineFixtures)。

当我奔跑

php composer.phar update

我得到

  - Updating twig/twig (dev-master 39d94fa => v1.13.0)
    The package has modified files:
    M CHANGELOG
    M doc/filters/batch.test
    M doc/filters/index.rst
    M doc/filters/url_encode.rst
    M doc/functions/index.rst
    M doc/tags/index.rst
    M doc/tests/index.rst
    M lib/Twig/Autoloader.php
    M lib/Twig/Compiler.php
    M lib/Twig/CompilerInterface.php
-10 more files modified, choose "v" to view the full list

看来上一个开发人员在供应商内部编辑了很多文件。

为了解决这个问题,我试过了

php composer.phar update <package_name>

但这似乎并不奏效。如何从composer.json中更新/安装一个库?


当前回答

在2.1版本中安装doctrine/doctrine-fixture -bundle。*和最小稳定性@dev使用这个:

composer require doctrine/doctrine-fixtures-bundle:2.1.*@dev

然后只更新这个包:

composer update doctrine/doctrine-fixtures-bundle

其他回答

因为你想安装特定的包 “我只需要为我的SF2发行版安装一个包(DoctrineFixtures)。”

php的作曲家。Phar需要package/package-name:package-version 这就足够了

你也可以按照下面的步骤来安装新包。

php composer.phar require

然后终端会要求你输入包的名称进行搜索。

$ Search for a package []: //Your package name here

然后终端会询问包的版本(如果你想要最新的版本,就把它留空)

$ Enter the version constraint to require (or leave blank to use the latest version) []: //your version number here

然后按回车键。终端会要求安装另一个软件包,如果你不想安装另一个,只要按回车键就可以了。

确保composer将已经安装的包更新到您在composer中设置的版本约束的最后一个版本。Json从供应商删除包,然后执行:

php composer.phar update vendor/package

如果你只是想更新一些包,而不是全部,你可以这样列出它们:

php composer.phar update vendor/package:2.* vendor/package2:dev-master

你也可以使用通配符一次更新一堆包:

php composer.phar update vendor/*

正如@ZeroThe2nd所评论的那样,ZSH用户可能需要将他们的供应商/*用引号括起来:

php composer.phar update "vendor/*"

--prefer-source: Install packages from source when available. --prefer-dist: Install packages from dist when available. --ignore-platform-reqs: ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill these. See also the platform config option. --dry-run: Simulate the command without actually doing anything. --dev: Install packages listed in require-dev (this is the default behavior). --no-dev: Skip installing packages listed in require-dev. The autoloader generation skips the autoload-dev rules. --no-autoloader: Skips autoloader generation. --no-scripts: Skips execution of scripts defined in composer.json. --no-plugins: Disables plugins. --no-progress: Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters. --optimize-autoloader (-o): Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default. --lock: Only updates the lock file hash to suppress warning about the lock file being out of date. --with-dependencies: Add also all dependencies of whitelisted packages to the whitelist. --prefer-stable: Prefer stable versions of dependencies. --prefer-lowest: Prefer lowest versions of dependencies. Useful for testing minimal versions of requirements, generally used with --prefer-stable.

在2.1版本中安装doctrine/doctrine-fixture -bundle。*和最小稳定性@dev使用这个:

composer require doctrine/doctrine-fixtures-bundle:2.1.*@dev

然后只更新这个包:

composer update doctrine/doctrine-fixtures-bundle