PHP code example of solid / bundle_version

1. Go to this page and download the library: Download solid/bundle_version library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

solid / bundle_version example snippets


use Solid\VersionChecker\Clients\GooglePlay\Exceptions\FailedToResolveGooglePlayVersionException;
use Solid\VersionChecker\Clients\GooglePlay\GooglePlayVersionResolver;
use GuzzleHttp\Client;

try {
    $resolver = new GooglePlayVersionResolver(new Client);
    $version = $this->resolver->resolve('com.app.example');

    echo $version->getBundleId() . ':' . $version->getCurrentRevision();
} catch(FailedToResolveGooglePlayVersionException $e) {
    echo 'Failed to resolve version';
}

use Solid\VersionChecker\Clients\AppStore\AppStoreVersionResolver;
use Solid\VersionChecker\Clients\AppStore\Exceptions\FailedToResolveAppStoreVersionException;
use GuzzleHttp\Client;

try {
    $resolver = new AppStoreVersionResolver(new Client);
    $version = $this->resolver->resolve('com.app.example');

    echo $version->getBundleId() . ':' . $version->getCurrentRevision();
} catch(FailedToResolveAppStoreVersionException $e) {
    echo 'Failed to resolve version';
}

use Solid\VersionChecker\Clients\GooglePlay\Exceptions\FailedToResolveGooglePlayVersionException;
use Solid\VersionChecker\Clients\GooglePlay\GooglePlayVersionResolver;
use Solid\VersionChecker\Clients\AppStore\AppStoreVersionResolver;
use Solid\VersionChecker\Clients\AppStore\Exceptions\FailedToResolveAppStoreVersionException;
use Solid\VersionChecker\Comparators\SemverComparator;
use Solid\VersionChecker\Enums\VersionCompareResultEnum;
use GuzzleHttp\Client;

try {
    $httpClient = new Client;
    $appStoreResolver = new AppStoreVersionResolver($httpClient);
    $googlePlayResolver = new GooglePlayVersionResolver($httpClient);

    $appStoreVersion = $this->resolver->resolve('com.app.example');
    $googlePlayVersion = $this->resolver->resolve('com.app.example');
    $comparator = new SemverComparator();
    $versionCompareResult = $comparator->compare($appStoreVersion->getCurrentRevision(), $googlePlayVersion->getCurrentRevision())

    if($versionCompareResult->is(VersionCompareResultEnum::MAJOR)) {
       echo 'App store has newer major release than play store';
    } else if($versionCompareResult->is(VersionCompareResultEnum::MINOR)) {
       echo 'App store has newer minor release than play store';
    } else if($versionCompareResult->is(VersionCompareResultEnum::PATCH)) {
       echo 'App store has newer patch release than play store';
    } else {
       echo 'App store and google play share same version';
    }
} catch(FailedToResolveAppStoreVersionException $e) {
    echo 'Failed to resolve app store version';
} catch(FailedToResolveGooglePlayVersionException $e) {
     echo 'Failed to resolve google play version';
}