protected function getLinuxDistribution($etcList = array())
{
// Get everything from /etc directory and flip the result for faster search,
// but only if there is no list provided already
$etcDir = '/etc';
if (empty($etcList)) {
$etcList = scandir($etcDir);
$etcList = array_flip($etcList);
}
// Loop through our mapping and look if we have a match
$distributionCandidates = array();
foreach ($this->distroMapping as $distribution => $releaseFile) {
// Do we have a match which is not just a soft link on the actual file? If so collect the distro
if (isset($etcList[$releaseFile]) && !is_link($etcDir . DIRECTORY_SEPARATOR . $releaseFile)) {
$distributionCandidates[$releaseFile] = $distribution;
}
}
// If we have several matches we might have to resort
if (count($distributionCandidates) === 1) {
return array_pop($distributionCandidates);
} elseif (count($distributionCandidates) > 1) {
// the file lsb-release might be existent in several Linux systems, filter it out
if (isset($distributionCandidates['lsb-release'])) {
unset($distributionCandidates['lsb-release']);
}
} else {
// It does not make sense to check any further
return false;
}
// Recursively filter the found files
return $this->getLinuxDistribution($distributionCandidates);
}