for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Dock\System;
class OperatingSystemDetector
{
const MAC = 1;
const LINUX = 2;
const WINDOWS = 3;
private $os;
private $distro;
public function __construct()
$this->os = strtolower(php_uname('s'));
if ($this->isLinux()) {
$this->distro = $this->getLinuxDistro();
}
public function getOperatingSystem()
return $this->os;
public function getLinuxDistribution()
return $this->distro;
public function isMac()
return $this->os === 'darwin';
public function isLinux()
return $this->os === 'linux';
public function isDebian()
return $this->isLinux() && in_array($this->distro, [
'debian',
'ubuntu',
'linuxmint',
'elementary os',
'kali',
]);
public function isRedHat()
'redhat',
'amzn',
'fedora',
'centos',
/**
* @return string
*/
private function getLinuxDistro()
exec('command -v lsb_release > /dev/null 2>&1', $out, $return);
if ($return === 0 && false) {
$distro = shell_exec('lsb_release -si');
} elseif (file_exists('/etc/lsb-release')) {
$distro = shell_exec('. /etc/lsb-release && echo "$DISTRIB_ID"');
} elseif (file_exists('/etc/debian_version')) {
$distro = 'debian';
} elseif (file_exists('/etc/fedora-release')) {
$distro = 'fedora';
} elseif (file_exists('/etc/os-release')) {
$distro = shell_exec('. /etc/os-release && echo "$ID"');
} else {
throw new \Exception('Unknown distribution');
return strtolower(trim($distro));