phpexperts/composer-constraints-parser

A clean-room implementation of Composer's version constraints parser.

v1.0.0 2025-04-16 10:23 UTC

This package is auto-updated.

Last update: 2025-04-16 10:26:27 UTC


README

Composer Constraints Parser is a PHP Experts, Inc., Project that is a clean-room implementation of Packagist's composer's version constraint system.

It is meant as a zero-dependency option to faithfully interpret whether any particular version number is satisfiable by a composer verison constraint.

NOTE: 95% of this code was generated by the autonomous AI agents of Autonomo, by Autonomous Programming, LLC. See https://gist.github.com/hopeseekr/fdb0ff9bd0957ea8d226ccc2def88d99

This project contains 100% of all of the in-the-world composer version constraints of every dependency of every package in the entire packagist.org database. These can be found in [tests/constraints.json].

There are 155,623 test assertions testing all 48,209 in-the-wild composer version constraints and has 100% fidelity. It is current as of 2025-04-01.

This is possible because of the Bettergist Collector API, which archives every PHP packagist package weekly and does deep analysis of them quarterly.

Installation

Via Composer

composer require phpexperts/composer-version-parser

Usage

use PHPExperts\ComposerVersionConstraints\ComposerConstraintsHelper;

$satisfies = ComposerConstraintsHelper::versionSatisfies('7.4', '^7.4|^8.0');
// true

Use cases

✔ Can determine if a constraint is valid
✔ Complex composer constraints
✔ All composer constraints
✔ Known constraint

Testing

phpunit

Contributors

Theodore R. Smith theodore@phpexperts.pro
GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
CEO: PHP Experts, Inc.

License

MIT license. Please see the license file for more information.