|
9 | 9 | use Symfony\Component\Process\ExecutableFinder; |
10 | 10 | use Symfony\Component\Process\PhpExecutableFinder; |
11 | 11 | use Symfony\Component\Process\Process; |
| 12 | +use Throwable; |
12 | 13 |
|
13 | 14 | trait InstallsRoadRunnerDependencies |
14 | 15 | { |
| 16 | + /** |
| 17 | + * The minimum required version of the RoadRunner binary. |
| 18 | + * |
| 19 | + * @var string |
| 20 | + */ |
| 21 | + protected $requiredVersion = '2.0.4'; |
| 22 | + |
15 | 23 | /** |
16 | 24 | * Determine if RoadRunner is installed. |
17 | 25 | * |
@@ -100,23 +108,74 @@ protected function ensureRoadRunnerBinaryIsInstalled(): string |
100 | 108 | } |
101 | 109 |
|
102 | 110 | if ($this->confirm('Unable to locate RoadRunner binary. Should Octane download the binary for your operating system?', true)) { |
103 | | - tap(new Process(array_filter([ |
104 | | - (new PhpExecutableFinder)->find(), |
105 | | - './vendor/bin/rr', |
106 | | - 'get-binary', |
107 | | - '-n', |
108 | | - '--ansi', |
109 | | - ]), base_path(), null, null, null))->run( |
110 | | - fn ($type, $buffer) => $this->output->write($buffer) |
| 111 | + $this->downloadRoadRunnerBinary(); |
| 112 | + |
| 113 | + copy(__DIR__.'/../stubs/rr.yaml', base_path('.rr.yaml')); |
| 114 | + } |
| 115 | + |
| 116 | + return base_path('rr'); |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * Ensure the RoadRunner binary installed in your project meets Octane requirements. |
| 121 | + * |
| 122 | + * @param string $roadRunnerBinary |
| 123 | + * @return void |
| 124 | + */ |
| 125 | + protected function ensureRoadRunnerBinaryMeetsRequirements($roadRunnerBinary) |
| 126 | + { |
| 127 | + $version = tap(new Process([$roadRunnerBinary, '--version'], base_path())) |
| 128 | + ->run() |
| 129 | + ->getOutput(); |
| 130 | + |
| 131 | + if (! Str::startsWith($version, 'rr version 2.')) { |
| 132 | + return $this->warn( |
| 133 | + 'Unable to determine the current RoadRunner binary version. Please report this issue: https://github.com/laravel/octane/issues/new.' |
111 | 134 | ); |
| 135 | + } |
112 | 136 |
|
113 | | - $this->line(''); |
| 137 | + $version = explode(' ', $version)[2]; |
114 | 138 |
|
115 | | - chmod(base_path('rr'), 755); |
| 139 | + if (version_compare($version, $this->requiredVersion, '<')) { |
| 140 | + $this->warn("Your RoadRunner binary version (<fg=red>$version</>) may be incompatible with Octane."); |
116 | 141 |
|
117 | | - copy(__DIR__.'/../stubs/rr.yaml', base_path('.rr.yaml')); |
| 142 | + if ($this->confirm('Should Octane download the latest RoadRunner binary version for your operating system?', true)) { |
| 143 | + rename($roadRunnerBinary, "$roadRunnerBinary.backup"); |
| 144 | + |
| 145 | + try { |
| 146 | + $this->downloadRoadRunnerBinary(); |
| 147 | + } catch (Throwable $e) { |
| 148 | + report($e); |
| 149 | + |
| 150 | + rename("$roadRunnerBinary.backup", $roadRunnerBinary); |
| 151 | + |
| 152 | + return $this->warn('Unable to download RoadRunner binary. The HTTP request exception has been logged.'); |
| 153 | + } |
| 154 | + |
| 155 | + unlink("$roadRunnerBinary.backup"); |
| 156 | + } |
118 | 157 | } |
| 158 | + } |
119 | 159 |
|
120 | | - return base_path('rr'); |
| 160 | + /** |
| 161 | + * Download the latest version of the RoadRunner binary. |
| 162 | + * |
| 163 | + * @return void |
| 164 | + */ |
| 165 | + protected function downloadRoadRunnerBinary() |
| 166 | + { |
| 167 | + tap(new Process(array_filter([ |
| 168 | + (new PhpExecutableFinder)->find(), |
| 169 | + './vendor/bin/rr', |
| 170 | + 'get-binary', |
| 171 | + '-n', |
| 172 | + '--ansi', |
| 173 | + ]), base_path(), null, null, null))->mustRun( |
| 174 | + fn ($type, $buffer) => $this->output->write($buffer) |
| 175 | + ); |
| 176 | + |
| 177 | + chmod(base_path('rr'), 755); |
| 178 | + |
| 179 | + $this->line(''); |
121 | 180 | } |
122 | 181 | } |
0 commit comments