Skip to content

Commit 5301e9f

Browse files
committed
Proof of concept
1 parent 0fecef5 commit 5301e9f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

app/Providers/AppServiceProvider.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
use App\Commands\ServeCommand;
88
use App\Commands\VendorPublishCommand;
99
use Illuminate\Support\ServiceProvider;
10+
use Humbug\SelfUpdate\Updater as PharUpdater;
11+
use LaravelZero\Framework\Providers\Build\Build;
12+
use LaravelZero\Framework\Components\Updater\Updater;
1013
use NunoMaduro\LaravelConsoleSummary\Contracts\DescriberContract;
14+
use LaravelZero\Framework\Components\Updater\Strategy\GithubStrategy;
15+
use LaravelZero\Framework\Components\Updater\Strategy\StrategyInterface;
1116

1217
class AppServiceProvider extends ServiceProvider
1318
{
@@ -37,5 +42,30 @@ public function boot(): void
3742

3843
// Register custom Laravel summary command describer implementation.
3944
$this->app->singleton(DescriberContract::class, Describer::class);
45+
46+
$build = $this->app->make(Build::class);
47+
48+
if ($build->isRunning() && $this->app->environment('production')) {
49+
$this->app->singleton(Updater::class, function () use ($build) {
50+
$updater = new PharUpdater($build->getPath(), false, PharUpdater::STRATEGY_GITHUB);
51+
52+
$composer = json_decode(file_get_contents(__DIR__.'/../../composer.json'), true);
53+
$name = $composer['name'];
54+
55+
$strategy = $this->app['config']->get('updater.strategy', GithubStrategy::class);
56+
57+
$updater->setStrategyObject($this->app->make($strategy));
58+
59+
if ($updater->getStrategy() instanceof StrategyInterface) {
60+
$updater->getStrategy()->setPackageName($name);
61+
}
62+
63+
if (method_exists($updater->getStrategy(), 'setCurrentLocalVersion')) {
64+
$updater->getStrategy()->setCurrentLocalVersion(config('app.version'));
65+
}
66+
67+
return new Updater($updater);
68+
});
69+
}
4070
}
4171
}

0 commit comments

Comments
 (0)