From 5301e9fe8017c0e0c8e87448e98eeddcdb7fbb0b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 12 Dec 2023 21:01:49 +0100 Subject: [PATCH] Proof of concept --- app/Providers/AppServiceProvider.php | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 35264a0c..7652d4fb 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -7,7 +7,12 @@ use App\Commands\ServeCommand; use App\Commands\VendorPublishCommand; use Illuminate\Support\ServiceProvider; +use Humbug\SelfUpdate\Updater as PharUpdater; +use LaravelZero\Framework\Providers\Build\Build; +use LaravelZero\Framework\Components\Updater\Updater; use NunoMaduro\LaravelConsoleSummary\Contracts\DescriberContract; +use LaravelZero\Framework\Components\Updater\Strategy\GithubStrategy; +use LaravelZero\Framework\Components\Updater\Strategy\StrategyInterface; class AppServiceProvider extends ServiceProvider { @@ -37,5 +42,30 @@ public function boot(): void // Register custom Laravel summary command describer implementation. $this->app->singleton(DescriberContract::class, Describer::class); + + $build = $this->app->make(Build::class); + + if ($build->isRunning() && $this->app->environment('production')) { + $this->app->singleton(Updater::class, function () use ($build) { + $updater = new PharUpdater($build->getPath(), false, PharUpdater::STRATEGY_GITHUB); + + $composer = json_decode(file_get_contents(__DIR__.'/../../composer.json'), true); + $name = $composer['name']; + + $strategy = $this->app['config']->get('updater.strategy', GithubStrategy::class); + + $updater->setStrategyObject($this->app->make($strategy)); + + if ($updater->getStrategy() instanceof StrategyInterface) { + $updater->getStrategy()->setPackageName($name); + } + + if (method_exists($updater->getStrategy(), 'setCurrentLocalVersion')) { + $updater->getStrategy()->setCurrentLocalVersion(config('app.version')); + } + + return new Updater($updater); + }); + } } }