Skip to content

Instantly share code, notes, and snippets.

@szepeviktor
Last active July 30, 2023 11:27
Show Gist options
  • Save szepeviktor/200b45f9805dc8bf3f185f0ade216987 to your computer and use it in GitHub Desktop.
Save szepeviktor/200b45f9805dc8bf3f185f0ade216987 to your computer and use it in GitHub Desktop.
Explain `composer require` prefer-* options

How Composer options control package selection

https://getcomposer.org/doc/04-schema.md

Stability

⚠️ Stability is not equal to version!

Possible values: dev, alpha, beta, RC, stable.

Defaults to stable.

  • Selected version must be stable: tagged with number-only tags.
    • Issue composer config minimum-stability stable
    • Add "minimum-stability": "stable" to composer.json
  • Selected version's stability can be lower, e.g. dev
    • Issue composer config minimum-stability dev
    • Add "minimum-stability": "dev" to composer.json

💡 Less stable versions are usually newer than stable ones.

Select a more stable version even when a less stable version is newer.

  • Issue composer config prefer-stable true
  • Add "prefer-stable": true to composer.json

Test compatibility with older versions

Version constrains allow a range of versions to be installed.

Select lowest versions possible: composer update --prefer-lowest

Preferred source for package download

Possible values: source, dist, auto.

Defaults to dist.

  • Use ZIP archive to download a package when available: Issue composer install --prefer-dist
  • Use git to download a package when available: Issue composer install --prefer-source

This can also be configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment