Skip to content

Commit f0efdfa

Browse files
authored
Merge pull request #483 from asgrim/482-fix-os-family-polyfill
482: fix PHP_OS_FAMILY missing in PHP <7.2 with polyfill
2 parents 0fd52a2 + 0dd84d6 commit f0efdfa

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/Platform/TargetPhp/PhpBinaryPath.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,38 @@ public function operatingSystem(): OperatingSystem
254254

255255
public function operatingSystemFamily(): OperatingSystemFamily
256256
{
257+
/** @link https://github.com/sebastianbergmann/environment/commit/eb6dd721cfaca04c27ac61c7201493a8f62f7f1d */
257258
$osFamily = OperatingSystemFamily::tryFrom(strtolower(trim(
258259
self::cleanWarningAndDeprecationsFromOutput(Process::run([
259260
$this->phpBinaryPath,
260261
'-r',
261-
'echo PHP_OS_FAMILY;',
262+
<<<'PHP'
263+
if (defined('PHP_OS_FAMILY')) {
264+
echo PHP_OS_FAMILY;
265+
} elseif ('\\' === DIRECTORY_SEPARATOR) {
266+
echo 'Windows';
267+
} else {
268+
switch(PHP_OS) {
269+
case 'Darwin':
270+
echo 'Darwin';
271+
break;
272+
case 'DragonFly':
273+
case 'FreeBSD':
274+
case 'NetBSD':
275+
case 'OpenBSD':
276+
echo 'BSD';
277+
break;
278+
case 'Linux':
279+
echo 'Linux';
280+
break;
281+
case 'SunOS':
282+
echo 'Solaris';
283+
break;
284+
default:
285+
echo 'Unknown';
286+
}
287+
}
288+
PHP,
262289
])),
263290
)));
264291
Assert::notNull($osFamily, 'Could not determine operating system family');

0 commit comments

Comments
 (0)