14
14
namespace LaravelZero \Framework \Components \Updater ;
15
15
16
16
use Humbug \SelfUpdate \Updater as PharUpdater ;
17
+ use Illuminate \Contracts \Config \Repository as ConfigRepository ;
17
18
use LaravelZero \Framework \Components \AbstractComponentProvider ;
18
19
use LaravelZero \Framework \Components \Updater \Strategy \GithubStrategy ;
19
20
use LaravelZero \Framework \Components \Updater \Strategy \StrategyInterface ;
20
21
use LaravelZero \Framework \Providers \Build \Build ;
22
+ use Phar ;
21
23
22
24
use function class_exists ;
23
25
@@ -31,7 +33,7 @@ final class Provider extends AbstractComponentProvider
31
33
*/
32
34
public function isAvailable (): bool
33
35
{
34
- return class_exists (\ Humbug \ SelfUpdate \Updater ::class);
36
+ return class_exists (PharUpdater ::class);
35
37
}
36
38
37
39
/**
@@ -67,19 +69,27 @@ public function register(): void
67
69
$ this ->app ->singleton (Updater::class, function () use ($ build ) {
68
70
$ updater = new PharUpdater ($ build ->getPath (), false , PharUpdater::STRATEGY_GITHUB );
69
71
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 );
72
73
73
- $ strategy = $ this ->app ['config ' ]->get ('updater.strategy ' , GithubStrategy::class);
74
+ /** @var ConfigRepository $config */
75
+ $ config = $ this ->app ->make (ConfigRepository::class);
74
76
75
- $ updater -> setStrategyObject ( $ this -> app -> make ( $ strategy) );
77
+ $ strategyClass = $ config -> get ( ' updater. strategy' , GithubStrategy::class );
76
78
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 ()));
79
89
}
80
90
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 ' ));
83
93
}
84
94
85
95
return new Updater ($ updater );
0 commit comments