Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 99025c9

Browse filesBrowse files
committed
fix: resolve Phar updater strategies
This makes sure that the Phar name is set for the GitHub Releases strategy.
1 parent 227b0fb commit 99025c9
Copy full SHA for 99025c9

File tree

Expand file treeCollapse file tree

5 files changed

+62
-19
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+62
-19
lines changed

‎src/Components/Updater/Provider.php

Copy file name to clipboardExpand all lines: src/Components/Updater/Provider.php
+19-9Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
namespace LaravelZero\Framework\Components\Updater;
1515

1616
use Humbug\SelfUpdate\Updater as PharUpdater;
17+
use Illuminate\Contracts\Config\Repository as ConfigRepository;
1718
use LaravelZero\Framework\Components\AbstractComponentProvider;
1819
use LaravelZero\Framework\Components\Updater\Strategy\GithubStrategy;
1920
use LaravelZero\Framework\Components\Updater\Strategy\StrategyInterface;
2021
use LaravelZero\Framework\Providers\Build\Build;
22+
use Phar;
2123

2224
use function class_exists;
2325

@@ -31,7 +33,7 @@ final class Provider extends AbstractComponentProvider
3133
*/
3234
public function isAvailable(): bool
3335
{
34-
return class_exists(\Humbug\SelfUpdate\Updater::class);
36+
return class_exists(PharUpdater::class);
3537
}
3638

3739
/**
@@ -67,19 +69,27 @@ public function register(): void
6769
$this->app->singleton(Updater::class, function () use ($build) {
6870
$updater = new PharUpdater($build->getPath(), false, PharUpdater::STRATEGY_GITHUB);
6971

70-
$composer = json_decode(file_get_contents(base_path('composer.json')), true);
71-
$name = $composer['name'];
72+
$composer = json_decode(file_get_contents($this->app->basePath('composer.json')), true);
7273

73-
$strategy = $this->app['config']->get('updater.strategy', GithubStrategy::class);
74+
/** @var ConfigRepository $config */
75+
$config = $this->app->make(ConfigRepository::class);
7476

75-
$updater->setStrategyObject($this->app->make($strategy));
77+
$strategyClass = $config->get('updater.strategy', GithubStrategy::class);
7678

77-
if ($updater->getStrategy() instanceof StrategyInterface) {
78-
$updater->getStrategy()->setPackageName($name);
79+
$updater->setStrategyObject($strategy = $this->app->make($strategyClass));
80+
81+
if ($strategy instanceof StrategyInterface) {
82+
assert(isset($composer['name']), 'Package name has not been set in Composer');
83+
84+
$strategy->setPackageName($composer['name']);
85+
}
86+
87+
if (method_exists($strategy, 'setPharName')) {
88+
$strategy->setPharName($config->get('updater.phar_name') ?? basename(Phar::running()));
7989
}
8090

81-
if (method_exists($updater->getStrategy(), 'setCurrentLocalVersion')) {
82-
$updater->getStrategy()->setCurrentLocalVersion(config('app.version'));
91+
if (method_exists($strategy, 'setCurrentLocalVersion')) {
92+
$strategy->setCurrentLocalVersion($config->get('app.version'));
8393
}
8494

8595
return new Updater($updater);
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LaravelZero\Framework\Components\Updater\Strategy\Concerns;
6+
7+
trait UsesPharName
8+
{
9+
private string $pharName;
10+
11+
public function setPharName($name): void
12+
{
13+
$this->pharName = $name;
14+
}
15+
16+
public function getPharName(): string
17+
{
18+
return $this->pharName;
19+
}
20+
}

‎src/Components/Updater/Strategy/GithubStrategy.php

Copy file name to clipboardExpand all lines: src/Components/Updater/Strategy/GithubStrategy.php
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22

33
namespace LaravelZero\Framework\Components\Updater\Strategy;
44

5-
use Phar;
5+
use LaravelZero\Framework\Components\Updater\Strategy\Concerns\UsesPharName;
66

77
final class GithubStrategy extends \Humbug\SelfUpdate\Strategy\GithubStrategy implements StrategyInterface
88
{
9-
/**
10-
* Returns the Download Url.
11-
*/
9+
use UsesPharName;
10+
1211
protected function getDownloadUrl(array $package): string
1312
{
1413
$downloadUrl = parent::getDownloadUrl($package);
1514

1615
$downloadUrl = str_replace('releases/download', 'raw', $downloadUrl);
1716

18-
return $downloadUrl.'/builds/'.basename(Phar::running());
17+
return "{$downloadUrl}/builds/{$this->getPharName()}";
1918
}
2019
}

‎src/Components/Updater/Strategy/GitlabStrategy.php

Copy file name to clipboardExpand all lines: src/Components/Updater/Strategy/GitlabStrategy.php
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22

33
namespace LaravelZero\Framework\Components\Updater\Strategy;
44

5-
use Phar;
5+
use LaravelZero\Framework\Components\Updater\Strategy\Concerns\UsesPharName;
66

77
class GitlabStrategy extends \Humbug\SelfUpdate\Strategy\GithubStrategy implements StrategyInterface
88
{
9-
/**
10-
* Returns the Download Url.
11-
*/
9+
use UsesPharName;
10+
1211
protected function getDownloadUrl(array $package): string
1312
{
1413
$downloadUrl = parent::getDownloadUrl($package);
1514

1615
$downloadUrl = str_replace('releases/download', '-/raw', $downloadUrl);
1716

18-
return $downloadUrl.'/builds/'.basename(Phar::running());
17+
return "{$downloadUrl}/builds/{$this->getPharName()}";
1918
}
2019
}

‎src/Components/Updater/config/updater.php

Copy file name to clipboardExpand all lines: src/Components/Updater/config/updater.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,19 @@
1717

1818
'strategy' => GithubStrategy::class,
1919

20+
/*
21+
|--------------------------------------------------------------------------
22+
| Self-updater Phar Name
23+
|--------------------------------------------------------------------------
24+
|
25+
| Here you may specify the name of the Phar file, as stored on GitHub or
26+
| GitLab. This can be configured if the Phar name is different to the
27+
| name of the Phar file running on the users' machine.
28+
|
29+
| Default: `null`
30+
|
31+
*/
32+
33+
'phar_name' => null,
34+
2035
];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.