/** * Query the config for a scope/variable. Returns the first value or scope on success, * or mDefault (default: null) if the query was not found. * @param string $sQuery The query string. e.g. "variable", "scope", "scope.variable", etc * @param mixed $mDefault The return value should the query not find anything. * @return string|ConfigFile|null The matching value from the query, or mDefault if not found */ public function get($sQuery, $mDefault = null) { $mVal = $mDefault; # try to get value match first if (array_key_exists($sQuery, $this->aValues) && count($this->aValues[$sQuery]) > 0) { $mVal = $this->aValues[$sQuery][0]; } else { # check if this matches any scopes $sScopeChar = preg_quote($this->sScopeDelimiter, "/"); $sQueryStr = preg_quote($sQuery, "/"); # must match a scope exactly ( "my.scope" should not match "my.scopeless" ) $sScopePattern = "/^{$sQueryStr}{$sScopeChar}(.+)\$/"; $aScopeMatches = array(); foreach ($this->aValues as $sName => $mValue) { if (preg_match($sScopePattern, $sName, $aMatch) === 1) { $aScopeMatches[$aMatch[1]] = $mValue; } } if (count($aScopeMatches) > 0) { $mVal = new ConfigFile(); $mVal->preload($aScopeMatches); } } return $mVal; }