PEAR_Config::_readConfigDataFrom PHP Method

_readConfigDataFrom() public method

Reads configuration data from a file and returns the parsed data in an array.
public _readConfigDataFrom ( $file ) : array
return array configuration data or a PEAR error on failure
    function _readConfigDataFrom($file)
    {
        $fp = false;
        if (file_exists($file)) {
            $fp = @fopen($file, "r");
        }
        if (!$fp) {
            return $this->raiseError("PEAR_Config::readConfigFile fopen('{$file}','r') failed");
        }
        $size = filesize($file);
        $rt = get_magic_quotes_runtime();
        set_magic_quotes_runtime(0);
        fclose($fp);
        $contents = file_get_contents($file);
        if (empty($contents)) {
            return $this->raiseError('Configuration file "' . $file . '" is empty');
        }
        set_magic_quotes_runtime($rt);
        $version = false;
        if (preg_match('/^#PEAR_Config\\s+(\\S+)\\s+/si', $contents, $matches)) {
            $version = $matches[1];
            $contents = substr($contents, strlen($matches[0]));
        } else {
            // Museum config file
            if (substr($contents, 0, 2) == 'a:') {
                $version = '0.1';
            }
        }
        if ($version && version_compare("{$version}", '1', '<')) {
            // no '@', it is possible that unserialize
            // raises a notice but it seems to block IO to
            // STDOUT if a '@' is used and a notice is raise
            $data = unserialize($contents);
            if (!is_array($data) && !$data) {
                if ($contents == serialize(false)) {
                    $data = array();
                } else {
                    $err = $this->raiseError("PEAR_Config: bad data in {$file}");
                    return $err;
                }
            }
            if (!is_array($data)) {
                if (strlen(trim($contents)) > 0) {
                    $error = "PEAR_Config: bad data in {$file}";
                    $err = $this->raiseError($error);
                    return $err;
                }
                $data = array();
            }
            // add parsing of newer formats here...
        } else {
            $err = $this->raiseError("{$file}: unknown version `{$version}'");
            return $err;
        }
        return $data;
    }