https://github.com/robertsaupe/php-phar-selfupdate
php library for phar selfupdate with a manifest file
https://github.com/robertsaupe/php-phar-selfupdate
library manifest phar php php8 selfupdate update
Last synced: 5 months ago
JSON representation
php library for phar selfupdate with a manifest file
- Host: GitHub
- URL: https://github.com/robertsaupe/php-phar-selfupdate
- Owner: robertsaupe
- License: mit
- Created: 2022-05-28T18:32:48.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-21T10:28:05.000Z (over 2 years ago)
- Last Synced: 2025-02-27T05:54:36.151Z (over 1 year ago)
- Topics: library, manifest, phar, php, php8, selfupdate, update
- Language: PHP
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# php-phar-selfupdate
[](https://packagist.org/packages/robertsaupe/php-phar-selfupdate)
[](https://packagist.org/packages/robertsaupe/php-phar-selfupdate)
[](https://packagist.org/packages/robertsaupe/php-phar-selfupdate)
[](LICENSE)
php library for phar selfupdate with a manifest file
## Supporting
[GitHub](https://github.com/sponsors/robertsaupe) |
[Patreon](https://www.patreon.com/robertsaupe) |
[PayPal](https://www.paypal.com/donate?hosted_button_id=SQMRNY8YVPCZQ) |
[Amazon](https://www.amazon.de/ref=as_li_ss_tl?ie=UTF8&linkCode=ll2&tag=robertsaupe-21&linkId=b79bc86cee906816af515980cb1db95e&language=de_DE)
## Installing
```sh
composer require robertsaupe/php-phar-selfupdate
```
## Getting started
### Update
```php
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);
}
```
### Update-Check
```php
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);
}
```
### Rollback
```php
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);
}
```
### manifest.json
```json
{
"1.0.1": {
"version": "1.0.1",
"url": "url_or_path_to\/1.0.1\/file.phar",
"sha1": "4f0dcc31a49417ee459abe5e73216f84a131fef3",
"sha256": "2e82de11605f73732ddf0948a6c2b7235cb139bb974c1ab88b1b5dc21fcb571f",
"sha512": "b356751b07e4626e043f65aeb85bf00b5a9933142652a17122abff0d43db3ce1371f212525b6aac011aa096592a5bcc85f14659fc2cd541f31ec2f4089931e91"
},
"1.0.0": {
"version": "1.0.0",
"url": "url_or_path_to\/1.0.0\/file.phar",
"sha1": "95743c0d18bde06ee15878092dd2edbe6f1d2e76",
"sha256": "5555f3d1f0567909e07bfc7cda29383cd63d9ad3d76aac88f43509904d916c23",
"sha512": "c9bf8e3712cb913dc067533909117ad17722ef6b4c869e47c1ce8c56cda2a1d182657063eaa713cca331584f2ac548465e87d88895779b4da0b52c62b9f70a2a"
}
}
```
### HashAlgo
#### Bash
```sh
sha1sum file.phar
sha256sum file.phar
sha512sum file.phar
```
#### PHP
```php
$sha1 = hash_file('sha1', 'file.phar');
$sha256 = hash_file('256', 'file.phar');
$sha512 = hash_file('512', 'file.phar');
```
## Credits
- [humbug/phar-updater](https://github.com/humbug/phar-updater) for basic phar updating
- Pádraic Brady
- [laravel-zero/phar-updater](https://github.com/laravel-zero/phar-updater) for the fork
- Owen Voke
- [ManifestStrategy](https://github.com/humbug/phar-updater/pull/37)
- Patrick Dawkins
- Pádraic Brady