Skip to content

Commit 30089a3

Browse files
committed
docs: add documentation for DirectDownloadStrategyAbstract
1 parent b2a9de3 commit 30089a3

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ The backend for the self-update command in Laravel Zero PHARs. Originally create
2525
- [Update Strategies](#update-strategies)
2626
- [SHA-1 / SHA-256 / SHA-512 Hash Synchronisation](#sha-1--sha-256--sha-512-hash-synchronisation)
2727
- [Github Releases](#github-releases)
28+
- [Direct Downloads](#direct-downloads)
2829

2930
## Introduction
3031

@@ -386,3 +387,48 @@ While you can draft a release, Github releases are created automatically wheneve
386387
git tagging, you can go to the matching release on Github, click the `Edit` button and attach files. It's recommended to
387388
do this as soon as possible after tagging to limit the window whereby a new release exists without an updated phar
388389
attached.
390+
391+
### Direct Downloads
392+
393+
PHAR Updater provides an abstract `Humbug\SelfUpdate\Strategy\DirectDownloadStrategyAbstract` class which can be used to
394+
quickly and easily create download strategies with just a `getDownloadUrl(): string` method.
395+
396+
For example, if a PHAR downloads it's latest updates from `https://example.com/latest/example.phar`, you can utilise this
397+
with the following code:
398+
399+
```php
400+
use Humbug\SelfUpdate\Strategy\DirectDownloadStrategyAbstract;
401+
402+
class ExampleDirectDownloadStrategy extends DirectDownloadStrategyAbstract
403+
{
404+
public function getDownloadUrl(): string
405+
{
406+
return 'https://example.com/latest/example.phar';
407+
}
408+
}
409+
```
410+
411+
The abstract strategy also supports overriding the `getCurrentRemoteVersion()` method, so that you could add a custom
412+
HTTP call or other method for seeing what the latest version is. By default, it returns the string `latest`.
413+
414+
```php
415+
use Illuminate\Support\Facades\Http;
416+
use Humbug\SelfUpdate\Strategy\DirectDownloadStrategyAbstract;
417+
418+
class ExampleDirectDownloadStrategy extends DirectDownloadStrategyAbstract
419+
{
420+
/** {@inheritdoc} */
421+
public function getCurrentRemoteVersion(Updater $updater)
422+
{
423+
return Http::get('https://example.com/example-releases.json')->json()['latest-version'];
424+
}
425+
426+
public function getDownloadUrl(): string
427+
{
428+
return 'https://example.com/{$this->getCurrentRemoteVersion()}/example.phar';
429+
}
430+
}
431+
```
432+
433+
You can also set and retrieve the current local version using the `setCurrentLocalVersion()` and `getCurrentLocalVersion()`
434+
methods, which will be used for comparison with the remote version.

0 commit comments

Comments
 (0)