Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/steevanb/php-version-comparator
Compare PHP version easier than with version_compare()
https://github.com/steevanb/php-version-comparator
Last synced: 9 days ago
JSON representation
Compare PHP version easier than with version_compare()
- Host: GitHub
- URL: https://github.com/steevanb/php-version-comparator
- Owner: steevanb
- License: mit
- Created: 2021-10-23T14:28:30.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-10-23T22:57:37.000Z (about 3 years ago)
- Last Synced: 2024-11-27T18:29:08.134Z (26 days ago)
- Language: PHP
- Homepage:
- Size: 52.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
[![Version](https://img.shields.io/badge/version-0.2.0-4B9081.svg)](https://github.com/steevanb/php-version-comparator/tree/0.2.0)
[![License](https://poser.pugx.org/steevanb/version-comparator/license)](https://github.com/steevanb/php-version-comparator/blob/master/LICENSE)
[![PHP](https://img.shields.io/badge/php-^5.3||^7.0||^8.0-blue.svg)](https://php.net)
![Lines](https://img.shields.io/badge/code%20lines-4,561-blue.svg)
![Downloads](https://poser.pugx.org/steevanb/version-comparator/downloads)[![CI](https://github.com/steevanb/php-version-comparator/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/steevanb/php-version-comparator/actions/workflows/ci.yml)
![Tests](https://img.shields.io/badge/tests-40-blue.svg)
![Assertions](https://img.shields.io/badge/assertions-70-blue.svg)
![Coverage](https://img.shields.io/badge/coverage-70%25-success.svg)
![Infection](https://img.shields.io/badge/infection-95%25-success.svg)## steevanb/version-comparator
Add classes to compare versions easier than with `compare_version()` and `PHP_VERSION`.
[Changelog](changelog.md)
## Installation
```
composer require steevanb/version-comparator ^0.2
```## Compare with current PHP version
You can compare current PHP version with 2 versions to know if current php version is between this 2 versions:
```php
PhpVersionComparator::isBetween('8', '9'); // return true is PHP is >= 8.0.0 and < 9.0.0
PhpVersionComparator::isBetween('8.0', '8.1'); // return true is PHP is >= 8.0.0 and < 8.1.0
PhpVersionComparator::isBetween('8.0.0', '8.0.2'); // return true is PHP is >= 8.0.0 and < 8.0.2
```## Shortcuts for each PHP major and minor version
`PhpVersionComparator` have a shortcut who call `isBetween()` for each major and minor version:
```php
// For PHP 5.3 to 5.6
PhpVersionComparator::isPhp5(); // return true is PHP is >= 5.0.0 and < 6.0.0
PhpVersionComparator::isPhp53(); // return true is PHP is >= 5.3.0 and < 5.4.0
PhpVersionComparator::isPhp54(); // return true is PHP is >= 5.4.0 and < 5.5.0
PhpVersionComparator::isPhp55(); // return true is PHP is >= 5.5.0 and < 5.6.0
PhpVersionComparator::isPhp56(); // return true is PHP is >= 5.6.0 and < 5.7.0// For PHP 7.0 to 7.4
PhpVersionComparator::isPhp7(); // return true is PHP is >= 7.0.0 and < 8.0.0
PhpVersionComparator::isPhp70(); // return true is PHP is >= 7.0.0 and < 7.1.0
PhpVersionComparator::isPhp71(); // return true is PHP is >= 7.1.0 and < 7.2.0
PhpVersionComparator::isPhp72(); // return true is PHP is >= 7.2.0 and < 7.3.0
PhpVersionComparator::isPhp73(); // return true is PHP is >= 7.3.0 and < 7.4.0
PhpVersionComparator::isPhp74(); // return true is PHP is >= 7.4.0 and < 7.5.0// For PHP 8.0 to latest 8.x
PhpVersionComparator::isPhp8(); // return true is PHP is >= 8.0.0 and < 9.0.0
PhpVersionComparator::isPhp80(); // return true is PHP is >= 8.0.0 and < 8.1.0
PhpVersionComparator::isPhp81(); // return true is PHP is >= 8.1.0 and < 8.2.0
```## Exception instead of returning the result
If you want to throw an exception instead of returning the result,
each method have it's `assert()` version who throw a `VersionIsNotBetweenException` exception:```php
PhpVersionComparator::assertIsBetween('8', '9');
PhpVersionComparator::assertIsPhp5();
// etc
```