composer/semver
PHP semantic version comparison, constraint parsing, and validation library from the Composer team
Repository Health
Technical Analysis
composer/semver is the standalone version-comparison engine extracted from Composer itself, providing version parsing, comparison, and constraint matching (^1.2, ~2.0, >=1.0 <2.0, etc.) as a reusable PHP library. It implements the same version constraint syntax Composer uses for require entries, so any PHP tool that needs to parse or evaluate version ranges can rely on identical semantics.
Beyond simple comparisons, the library includes an Intervals class for normalizing and merging overlapping version constraints, and a CompilingMatcher that compiles constraint checks into optimized PHP closures for performance-sensitive repeated matching, such as resolving dependencies across a large package repository.
What You Get
Semverstatic facade for satisfies/sort/filter operations against version constraintsVersionParserfor normalizing arbitrary version strings into comparable canonical formsComparatorfor direct version comparisons (greaterThan, lessThan, equalTo, etc.)- Full support for Composer’s constraint syntax (caret, tilde, wildcard, range operators)
Intervalsclass for normalizing and merging overlapping version constraint rangesCompilingMatcherthat compiles a constraint into a reusable closure for fast repeated matching
Common Use Cases
- Validating that an installed package version satisfies a required version constraint
- Building custom PHP package managers or plugin systems that need Composer-compatible version syntax
- Sorting or filtering a list of version strings/tags according to semantic versioning rules
- Resolving and merging multiple version constraints when building dependency graphs
Under The Hood
Architecture - The library is a small, focused set of classes: VersionParser.php normalizes raw version strings (including pre-release/stability suffixes) into a canonical form; Constraint/ holds the constraint object model (multi-constraint AND/OR trees, single constraints); Comparator.php and Semver.php provide the comparison and satisfies/sort/filter facade respectively; Intervals.php normalizes and merges sets of constraints into non-overlapping intervals; CompilingMatcher.php compiles a constraint into a PHP closure to avoid repeated parsing overhead when the same constraint is checked against many versions.
Tech Stack - Pure PHP with no runtime dependencies beyond the PHP standard library, keeping it trivially embeddable in any PHP project regardless of framework.
Code Quality - The tests/ directory (10+ test files) covers version parsing edge cases, constraint satisfaction, and interval merging; PHPStan with a maintained baseline enforces static analysis. As the extracted, battle-tested core of Composer’s own dependency resolver — used by essentially the entire PHP ecosystem via Composer itself — its correctness has been validated at massive scale in production.
API Design - The Semver facade class offers a small number of static methods (satisfies, satisfiedBy, sort, rsort) covering the common cases in one line, while the underlying VersionParser/Constraint object model is available directly for tools that need finer control, such as building a custom dependency resolver.
Used by 4 apps in this directory
Craft CMS
CMS
A developer-first PHP CMS with clean-slate content modeling, auto-generated GraphQL API, and a four-tier edition system that scales from solo projects to enterprise deployments.
EspoCRM
Marketing · Ecommerce · CRM
Open-source CRM platform with metadata-driven customization, field-level permissions, and a full REST API — deploy on your own infrastructure.
Kimai
Invoicing Finance · Project Management
Professional open-source time tracking with invoicing, multi-user support, SAML/LDAP auth, and a full REST API—self-host it or use the cloud.
matomo
Analytics
Open-source, privacy-first web and app analytics that puts you in complete control of your data.