forked from humbug/phar-updater
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDirectDownloadStrategyAbstract.php
47 lines (38 loc) · 1.23 KB
/
DirectDownloadStrategyAbstract.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Humbug\SelfUpdate\Strategy;
use Humbug\SelfUpdate\Exception\HttpRequestException;
use Humbug\SelfUpdate\Updater;
abstract class DirectDownloadStrategyAbstract implements StrategyInterface
{
protected string $localVersion;
abstract public function getDownloadUrl(): string;
/** {@inheritdoc} */
public function download(Updater $updater)
{
/** Switch remote request errors to HttpRequestExceptions */
set_error_handler([$updater, 'throwHttpRequestException']);
$result = file_get_contents($this->getDownloadUrl());
restore_error_handler();
if (false === $result) {
throw new HttpRequestException(sprintf(
'Request to URL failed: %s',
$this->getDownloadUrl()
));
}
file_put_contents($updater->getTempPharFile(), $result);
}
/** {@inheritdoc} */
public function getCurrentRemoteVersion(Updater $updater)
{
return 'latest';
}
public function setCurrentLocalVersion(string $version): void
{
$this->localVersion = $version;
}
/** {@inheritdoc} */
public function getCurrentLocalVersion(Updater $updater)
{
return $this->localVersion;
}
}