Download the PHP package someshwer/version-comparison without Composer

On this page you can find all versions of the php package someshwer/version-comparison. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package version-comparison

version-comparison

Total Downloads Latest Stable Version Latest Unstable Version

This Laravel package compares two version strings and gives the Boolean result. This package also resolves version expressions like (($v > 1.24.0) && ($v < 1.25.1.0)) || ($v == 1.26 || $v == 1.27) where $v must be substituted with the version number to be compared. Hence the package can be used for version expressions evaluation.

Installation

To download the latest version, type the following line in terminal and then press enter. (Current stable version of this package is 2.1 LTS)

composer require someshwer/version-comparison

And then add the following service provider to providers array in config/app.php configuration file.

Ex: 'providers' => [
        ... ,
        ... ,
        Someshwer\VersionComparison\VersionComparisonServiceProvider::class
    ]; 

And add the following alias to aliases array in config/app.php configuration file.

Ex: 'aliases' => [
        ... ,
        .... ,
        'VersionComparator' => Someshwer\VersionComparison\Facades\VersionComparator::class
    ]; 

Now just simply publish the service provider by running following command in terminal. (Optional Step)

    $ php artisan vendor:publish --provider="Someshwer\VersionComparison\VersionComparisonServiceProvider"

    That's all! You are done with package installation...

Usage

  1. VersionComparator::compare(): This method compares two version strings using specified operator and gives the Boolean result. It takes three parameters:

    VersionComparator::compare(Version1 String, Operator String, Version2 String); // compare(Version1, Operator, Version2);

    a. Version number (First Parameter) b. Operator (Second Parameter) c. Version number (Third Parameter)

    Ex: VersionComparator::compare('1.2.5', '>', '1.2.2'); // Gives the Boolean result either TRUE or FALSE. For this above example comparison, the result is TRUE.

  2. VersionComparator::evaluate(): This method usually evaluates version expression in the following form: (("1.2" > "1.24.0") && ("1.2" < "1.25.1.0")) || ("1.2" == "1.26" || "1.2" == "1.27") It takes only one argument that is expression of the above type.

    VersionComparator::evaluate('Version Expression');

    Ex: VersionComparator::evaluate('(("1.2" > "1.24.0") && ("1.2" < "1.25.1.0")) || ("1.2" == "1.26" || "1.2" == "1.27")'); // Gives Boolean result either TRUE or FALSE

  3. VersionComparator::substituteThenEvaluate(): This method usually evaluates version expressions of the following type: (($v > "1.24.0") && ($v < "1.25.1.0")) || ($v == "1.26" || $v == "1.27") This method takes two parameters. They are: a. First one is the version number to be substituted in place of $v in the expression. And b. The second one is the expression to be evaluated after $v is substituted.

    Note: $v is the variable to be substituted with version number (First Parameter).

    VersionComparator::substituteThenEvaluate('Version Number', 'Version Expression');

    Ex: VersionComparator::substituteThenEvaluate('2.1.4', '((1.2 > 1.24.0) && (1.2 < 1.25.1.0)) || (1.2 == 1.26 || 1.2 == 1.27)'); Hence, in this example: $v in the expression is replaced by '2.1.4'.

    After successful evaluation it gives the Boolean result either TRUE or FLASE.

    Note: This package requires and depends on two other external third-party packages. They are:

    1. composer/semver version 1.4.2 (https://github.com/composer/semver) and
    2. symfony/expression-language version 4.1 (https://symfony.com/doc/current/components/expression_language.html).

    You no need to manually install them in your project. They will be automatically downloaded to your vendor folder when ever you install "someshwer/version-comparison" package by executing the following command in terminal.

    -> composer require someshwer/version-comparison

Response

The response content must be json. The methods of this package almost always return the response in JSON format.

Example:

1. Sample success response:
{
   status: "SUCCESS",
   message: "Expression successfully evaluated!",
   error_message: false,
}

2. Sample validation error response:
{
   status: "ERROR",
   error_type: "validation",
   message: "Unable to evaluate the expression!",
   error_message: "Invalid expression! Unexpected ")" around position 44 for expression `(('1.2' > '1.24.0')) && ('1.2' < '1.25.1.0')) || ('1.2' == '1.26' || '1.2' == '1.27')`. Check log for more info.",
}

Note: If you want, you can also customize the response to the format which ever you want.!

Code snippet for testing:

Route::get('/test', function () {

     $result_one = \VersionComparator::compare('1.2.8', '>', '1.2');

     $result_two = \VersionComparator::evaluate('((1.2.8 > 1.24.0) && (1.2.8 < 1.25.1.0)) || (1.2.8 == 1.26 || 1.2.8 == 1.27)');

     $result_three = \VersionComparator::substituteThenEvaluate('1.2', '(($v > 1.24.0) && ($v < 1.25.1.0)) || ($v == 1.26 || $v == 1.27)');

     // return compact('result_one', 'result_two', 'result_three');

     // return $result_one;
     // return $result_two;
     return $result_three;

});

If you want to test this package, copy and paste the above code in your web.php file and test this version-comparison/version-expression evaluation package.

Screenshot of code snippet:

alt Code Snippet Screen Shot


All versions of version-comparison with dependencies

PHP Build Version
Package Version
Requires php Version ^5.4 || ^7.0
composer/semver Version ^1.4
symfony/expression-language Version ^4.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package someshwer/version-comparison contains the following files

Loading the files please wait ...