PHP code example of robertsaupe / php-phar-selfupdate

1. Go to this page and download the library: Download robertsaupe/php-phar-selfupdate 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/ */

    

robertsaupe / php-phar-selfupdate example snippets


use Exception;
use robertsaupe\Phar\SelfUpdate\ManifestUpdate;

$updater = new ManifestUpdate('1.0.0', 'path_to_manifest.json');

try {
    $result = $updater->update();
    $newVersion = $updater->getNewVersion();
    $oldVersion = $updater->getOldVersion();
    if ($result) {
        print('Phar has been updated.'.PHP_EOL);
        print('Current version is: '.$newVersion.PHP_EOL);
        print('Previous version was: '.$oldVersion.PHP_EOL);
    } else {
        print('Phar is currently up to date.'.PHP_EOL);
        print('Current version is: '.$oldVersion.PHP_EOL);
    }
} catch (Exception $e) {
    print('Error: '.$e->getMessage().PHP_EOL);
}

use Exception;
use robertsaupe\Phar\SelfUpdate\ManifestUpdate;

$updater = new ManifestUpdate('1.0.0', 'path_to_manifest.json');

print('The current local version is: '.$updater->getCurrentLocalVersion().PHP_EOL);

try {
    $result = $updater->getCurrentRemoteVersion();
    if ($result) {
        print('The current '.$updater->getStability().' build available remotely is: '.$result.PHP_EOL);
    } else {
        print('You have the current '.$updater->getStability().' build installed.'.PHP_EOL);
    }
} catch (Exception $e) {
    print('Error: '.$e->getMessage().PHP_EOL);
}

use Exception;
use robertsaupe\Phar\SelfUpdate\ManifestUpdate;

$updater = new ManifestUpdate('1.0.0', 'path_to_manifest.json');

try {
    $result = $updater->rollback();
    if ($result) {
        print('Phar has been rolled back to prior version.'.PHP_EOL);
    } else {
        print('Rollback failed for reasons unknown.'.PHP_EOL);
    }
} catch (Exception $e) {
    print('Error: '.$e->getMessage().PHP_EOL);
}

$sha1 = hash_file('sha1', 'file.phar');
$sha256 = hash_file('256', 'file.phar');
$sha512 = hash_file('512', 'file.phar');
sh
sha1sum file.phar
sha256sum file.phar
sha512sum file.phar