AppserverIo\Appserver\Core\Scanner\AbstractScanner::getDistributionVersion PHP Method

getDistributionVersion() protected method

This method will check for the Linux release file normally stored in /etc and will return the version of the distribution
protected getDistributionVersion ( string | null $distribution = null, array $etcList = [] ) : string | boolean
$distribution string | null Distribution to search a version for
$etcList array List of already collected AND flipped release files we need to filter
return string | boolean
    protected function getDistributionVersion($distribution = null, $etcList = array())
    {
        // Get everything from /etc directory and flip the result for faster search,
        // but only if there is no list provided already
        $etcDir = $this->getEtcDir();
        if (empty($etcList)) {
            $etcList = scandir($etcDir);
            $etcList = array_flip($etcList);
        }
        // check if we got a distribution to specifically look for, if not determine it first
        if (is_null($distribution)) {
            $distribution = $this->getLinuxDistribution($etcList);
        }
        // check if the distribution was properly provided/found, if not return FALSE
        if (!isset($this->distroMapping[$distribution])) {
            return false;
        }
        // loop through our mapping and look if we have a match
        $releaseFile = $this->distroMapping[$distribution];
        // do we have a match which is not just a soft link on the actual file? If so collect the file content
        $potentialVersion = '';
        if (isset($etcList[$releaseFile]) && !is_link($etcDir . DIRECTORY_SEPARATOR . $releaseFile)) {
            // retrieve the version string and try to determine the actual version from it
            $potentialVersion = file_get_contents($etcDir . DIRECTORY_SEPARATOR . $releaseFile);
            $matches = array();
            preg_match('/(\\d+\\.*)+/', $potentialVersion, $matches);
            // filter our findings
            if (!isset($matches[0])) {
                return false;
            }
            $potentialVersion = $matches[0];
        }
        // return what we got
        return $potentialVersion;
    }