Skip to content

Commit

Permalink
Proof of concept
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 13, 2023
1 parent 0fecef5 commit 5301e9f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
});
}
}
}

0 comments on commit 5301e9f

Please sign in to comment.