Skip to content

Commit f05d3e0

Browse files
committed
Fixes #287
1 parent 9683607 commit f05d3e0

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

src/Commands/Concerns/InstallsRoadRunnerDependencies.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Str;
66
use RuntimeException;
77
use Spiral\RoadRunner\Http\PSR7Worker;
8+
use Laravel\Octane\RoadRunner\Concerns\FindsRoadRunnerBinary;
89
use Symfony\Component\Process\Exception\ProcessSignaledException;
910
use Symfony\Component\Process\ExecutableFinder;
1011
use Symfony\Component\Process\PhpExecutableFinder;
@@ -13,6 +14,8 @@
1314

1415
trait InstallsRoadRunnerDependencies
1516
{
17+
use FindsRoadRunnerBinary;
18+
1619
/**
1720
* The minimum required version of the RoadRunner binary.
1821
*
@@ -97,14 +100,8 @@ protected function findComposer()
97100
*/
98101
protected function ensureRoadRunnerBinaryIsInstalled(): string
99102
{
100-
if (file_exists(base_path('rr'))) {
101-
return base_path('rr');
102-
}
103-
104-
if (! is_null($roadRunnerBinary = (new ExecutableFinder)->find('rr', null, [base_path()]))) {
105-
if (! Str::contains($roadRunnerBinary, 'vendor/bin/rr')) {
106-
return $roadRunnerBinary;
107-
}
103+
if (! is_null($roadRunnerBinary = $this->findRoadRunnerBinary())) {
104+
return $roadRunnerBinary;
108105
}
109106

110107
if ($this->confirm('Unable to locate RoadRunner binary. Should Octane download the binary for your operating system?', true)) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Laravel\Octane\RoadRunner\Concerns;
4+
5+
use Illuminate\Support\Str;
6+
use Symfony\Component\Process\ExecutableFinder;
7+
8+
trait FindsRoadRunnerBinary
9+
{
10+
protected function findRoadRunnerBinary(): ?string
11+
{
12+
if (file_exists(base_path('rr'))) {
13+
return base_path('rr');
14+
}
15+
16+
if (! is_null($roadRunnerBinary = (new ExecutableFinder)->find('rr', null, [base_path()]))) {
17+
if (! Str::contains($roadRunnerBinary, 'vendor/bin/rr')) {
18+
return $roadRunnerBinary;
19+
}
20+
}
21+
22+
return null;
23+
}
24+
}

src/RoadRunner/ServerProcessInspector.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
use Laravel\Octane\SymfonyProcessFactory;
77
use RuntimeException;
88
use Symfony\Component\Process\Process;
9+
use Laravel\Octane\RoadRunner\Concerns\FindsRoadRunnerBinary;
910

1011
class ServerProcessInspector
1112
{
13+
use FindsRoadRunnerBinary;
14+
1215
public function __construct(
1316
protected ServerStateFile $serverStateFile,
1417
protected SymfonyProcessFactory $processFactory,
@@ -45,7 +48,7 @@ public function reloadServer(): void
4548
] = $this->serverStateFile->read();
4649

4750
tap($this->processFactory->createProcess([
48-
'./rr',
51+
$this->findRoadRunnerBinary(),
4952
'reset',
5053
'-o', "rpc.listen=tcp://$host:$rpcPort",
5154
], base_path()))->start()->waitUntil(function ($type, $buffer) {

tests/RoadRunnerServerProcessInspectorTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
use Laravel\Octane\RoadRunner\ServerStateFile;
88
use Laravel\Octane\SymfonyProcessFactory;
99
use Mockery;
10+
use Laravel\Octane\RoadRunner\Concerns\FindsRoadRunnerBinary;
1011

1112
class RoadRunnerServerProcessInspectorTest extends TestCase
1213
{
14+
use FindsRoadRunnerBinary;
15+
1316
public function test_can_determine_if_roadrunner_server_process_is_running_when_master_is_running()
1417
{
1518
$inspector = new ServerProcessInspector(
@@ -59,7 +62,7 @@ public function test_roadrunner_server_process_can_be_reloaded()
5962
]);
6063

6164
$processFactory->shouldReceive('createProcess')->with(
62-
['./rr', 'reset', '-o', 'rpc.listen=tcp://127.0.0.1:6002'],
65+
[$this->findRoadRunnerBinary(), 'reset', '-o', 'rpc.listen=tcp://127.0.0.1:6002'],
6366
base_path(),
6467
)->andReturn($process = Mockery::mock('stdClass'));
6568

0 commit comments

Comments
 (0)