https://github.com/php-mod/version
Versions and Constraints for PHP
https://github.com/php-mod/version
Last synced: 10 months ago
JSON representation
Versions and Constraints for PHP
- Host: GitHub
- URL: https://github.com/php-mod/version
- Owner: php-mod
- License: mit
- Created: 2014-10-18T02:23:21.000Z (over 11 years ago)
- Default Branch: 2.x
- Last Pushed: 2019-11-14T17:15:35.000Z (about 6 years ago)
- Last Synced: 2025-03-24T21:22:23.096Z (10 months ago)
- Language: PHP
- Homepage:
- Size: 55.7 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: LICENSE.md
Awesome Lists containing this project
README
Versions and Constraints for PHP
================================
This library parse versions,
E.x.:
1.0.0
1.0.2-stable
1.0.20-alpha2.
It can parse constraints (like Composer versions),
E.x.:
>=1.0 >=1.0,<2.0 >=1.0,<1.1 | >=1.2,
1.0.*,
~1.2.
The goal of that is to let you check if a version matches a constraint,
or to check if a constraint is a subset of another constraint.
All that is done to let us select which version is compatible with a user constraints.
It works with the same rules of Composer versioning.
### Sorting
In order to use standard PHP sorting there is a helper class 'Compare' to use it with a sort you will need to do this;
```php
use Version\Version;
use Version\Compare;
$vers = array();
$vers[] = Version::parse('1.1.1d1');
$vers[] = '1.1.1';
$obj = new Compare();
usort( $vers, array( $obj, 'compare' ) );
```
The above should allow any normal PHP sort to be instigated with very little effort.
**Note**: You should see that it will handle a string or a Version object as the variable to sort automatically.