Skip to content

Commit 85f40cd

Browse files
authored
[2.x] Improves version fetching (#779)
* Uses `build-info` instead * Fix code styling * Dont uses const on traits --------- Co-authored-by: nunomaduro <[email protected]>
1 parent 42ce8da commit 85f40cd

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/Commands/Concerns/InstallsFrankenPhpDependencies.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use GuzzleHttp\Client;
66
use Illuminate\Support\Facades\Http;
7+
use Illuminate\Support\Str;
78
use Laravel\Octane\FrankenPhp\Concerns\FindsFrankenPhpBinary;
89
use Symfony\Component\Process\Process;
910
use Throwable;
@@ -126,13 +127,24 @@ protected function downloadFrankenPhpBinary()
126127
*/
127128
protected function ensureFrankenPhpBinaryMeetsRequirements($frakenPhpBinary)
128129
{
129-
$version = tap(new Process([$frakenPhpBinary, '--version'], base_path()))
130+
$buildInfo = tap(new Process([$frakenPhpBinary, 'build-info'], base_path()))
130131
->run()
131132
->getOutput();
132133

133-
$version = explode(' ', $version)[1] ?? null;
134+
$lineWithVersion = collect(explode("\n", $buildInfo))
135+
->first(function ($line) {
136+
return str_starts_with($line, 'dep') && str_contains($line, 'github.com/dunglas/frankenphp');
137+
});
134138

135-
if ($version === null || preg_match('/\d+\.\d+\.\d+/', $version) !== 1) {
139+
if ($lineWithVersion === null) {
140+
return $this->warn(
141+
'Unable to determine the current FrankenPHP binary version. Please report this issue: https://github.com/laravel/octane/issues/new.',
142+
);
143+
}
144+
145+
$version = Str::of($lineWithVersion)->trim()->afterLast('v')->value();
146+
147+
if (preg_match('/\d+\.\d+\.\d+/', $version) !== 1) {
136148
return $this->warn(
137149
'Unable to determine the current FrankenPHP binary version. Please report this issue: https://github.com/laravel/octane/issues/new.',
138150
);

0 commit comments

Comments
 (0)