|
7 | 7 | use App\Commands\ServeCommand;
|
8 | 8 | use App\Commands\VendorPublishCommand;
|
9 | 9 | 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; |
10 | 13 | use NunoMaduro\LaravelConsoleSummary\Contracts\DescriberContract;
|
| 14 | +use LaravelZero\Framework\Components\Updater\Strategy\GithubStrategy; |
| 15 | +use LaravelZero\Framework\Components\Updater\Strategy\StrategyInterface; |
11 | 16 |
|
12 | 17 | class AppServiceProvider extends ServiceProvider
|
13 | 18 | {
|
@@ -37,5 +42,30 @@ public function boot(): void
|
37 | 42 |
|
38 | 43 | // Register custom Laravel summary command describer implementation.
|
39 | 44 | $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 | + } |
40 | 70 | }
|
41 | 71 | }
|
0 commit comments