Skip to content

Commit 0577b22

Browse files
committed
Merge pull request #112 from devnuhl/master
Check php-cgi --version on instantiation, and die with message if unable.
2 parents 409365a + 0ac4a9f commit 0577b22

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Application.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ public function run()
166166
)
167167
);
168168
return 1;
169+
} catch (\RuntimeException $e) {
170+
$container
171+
->get(OutputInterface::class)
172+
->printError(
173+
sprintf(
174+
'%s',
175+
$e->getMessage()
176+
)
177+
);
178+
return 1;
169179
}
170180
return $exitCode;
171181
}

src/ExerciseRunner/CgiRunner.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,28 @@ class CgiRunner implements ExerciseRunnerInterface
4343
*/
4444
public function __construct(CgiExercise $exercise, EventDispatcher $eventDispatcher)
4545
{
46+
if (strpos(PHP_OS, 'WIN') !== false) {
47+
// Check if in path. 2> nul > nul equivalent to 2>&1 /dev/null
48+
$silence = (PHP_OS == 'CYGWIN' ? '> /dev/null 2>&1' : '2> nul > nul');
49+
system(sprintf('php-cgi --version %s', $silence), $failedToRun);
50+
if ($failedToRun) {
51+
$newPath = realpath(sprintf('%s/%s', dirname(PHP_BINARY), 'php-cgi.exe'));
52+
// Try one more time, relying on being in the php binary's directory (where it should be on Windows)
53+
system(sprintf('%s --version %s', $newPath, $silence), $stillFailedToRun);
54+
if ($stillFailedToRun) {
55+
throw new \RuntimeException(
56+
'Could not load php-cgi binary. Please install php-cgi using your package manager.'
57+
);
58+
}
59+
}
60+
} else {
61+
@system('php-cgi --version > /dev/null 2>&1', $failedToRun);
62+
if ($failedToRun) {
63+
throw new \RuntimeException(
64+
'Could not load php-cgi binary. Please install php-cgi using your package manager.'
65+
);
66+
}
67+
}
4668
$this->eventDispatcher = $eventDispatcher;
4769
$this->exercise = $exercise;
4870
}

0 commit comments

Comments
 (0)